砍敺 media 2014-12-10 19:08 蝺刻摩 3 ]) t* z2 k# @$ w
/ f/ O1 ^$ }1 I
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
; R" }$ X+ b; p3 ]6 Z. P1 s- <script type="text/javascript"> t5 n. e# |, C
- <!--. a* A) a( e, G4 ?* M3 ~8 L% |% ^
3 T* E% M! L8 O9 O6 O- var viewportwidth;
( j5 D/ C0 U6 {- ^ - var viewportheight;/ Y/ a7 _) I$ k' G
-
, c* q' b3 ?( _9 ]6 Z - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight6 S9 K* N: K- G9 Z3 X; t( p
- " x. N7 Q0 S( q* C/ s* v) Y# B$ Q
- if (typeof window.innerWidth != 'undefined')* b4 x5 K1 L5 ~" O2 Y- i, S/ z
- {
6 p4 Z. i" k- e) _0 _' f - viewportwidth = window.innerWidth,* d" e3 S; N) A1 A# {, |- O
- viewportheight = window.innerHeight' @7 N# u5 J" F5 I `, X
- }/ B7 w, @, p- I0 }1 z) E8 p& T
-
E" |+ l0 K$ M' }1 L/ q - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
* \$ j% m+ p$ w5 [- Z: K: z - . T7 ^ q/ N" r# Y( \
- else if (typeof document.documentElement != 'undefined'
# o% q/ C, H* v5 L - && typeof document.documentElement.clientWidth !=- M0 c7 r) c8 W4 d) O' Q
- 'undefined' && document.documentElement.clientWidth != 0), [" {" P4 B$ q1 x" l* Z
- {
# N9 }+ h" ^' d; ? - viewportwidth = document.documentElement.clientWidth,
( o2 H/ }( I8 b% c: n C7 l& S - viewportheight = document.documentElement.clientHeight9 j% ?' r: a1 }# Q w/ U/ _
- }
1 g1 I7 n7 x% }3 Q% v' k - * \8 K% e8 C3 ` \% B! U" q
- // older versions of IE( s: o$ h( X, g! Y r. Z
- ; m' M* y: a% x. B7 i, k; ?
- else6 v* z. @( e8 q
- {( B W0 r) N+ O/ @8 ^
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,6 g( v% Q6 M' X9 {% K7 v
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
7 s) z% b1 s* E( z( k - }1 |/ E1 {: G; R3 I
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');) `! n) w- x5 _% _+ |3 g
- //-->
( C3 ~1 ^* A* F8 E4 C7 _ - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
7 c, |- M* E4 X' `" T
% ^# c/ L1 g: b/ c
) V& R- ^2 s. a. ]) O$ p1 C靘皞: Get viewport size (width and height) with javascript2 V; }0 z+ p( N8 l4 M) S# U
2 z" u* q" {' ]# R
* t( `. C! i& V' b% O7 d |
|