砍敺 media 2014-12-10 19:08 蝺刻摩
: ^3 w5 y0 ^! Z' u7 Z- g2 b. D! e( L* P2 T) Y0 F6 x
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具 G n5 G* w# [- j& G7 w
- <script type="text/javascript"># B+ w" E# |# _# V l R
- <!--5 `% @4 x4 `* ]( E/ p7 p- U
- E/ a6 l/ s9 w! I- v" y8 g
- var viewportwidth;. S( _8 `1 ~. P; [! h3 n8 ~
- var viewportheight;
5 n+ A( ]* x1 z -
) n! e4 _3 o( x/ x. K" P - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
1 r B' i5 ?( Y3 H' ? - 2 {) r/ l, [: U; Z$ d
- if (typeof window.innerWidth != 'undefined')' q! Y3 m. s& }0 G& v
- { F$ x$ U/ q2 }$ a$ s9 q7 X
- viewportwidth = window.innerWidth,
7 e) e" z) f. g9 y! T6 y) G - viewportheight = window.innerHeight% x- G' m! l8 R M D6 O& X
- }
) K* o+ Y3 B6 W4 I -
& B; L) C h6 p$ F' B! M - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)8 J* g s$ L) v; j2 N8 ?) {7 } }4 y! o
4 ?* j& r) j* @- B4 R- else if (typeof document.documentElement != 'undefined'! H8 d5 _) R& q2 L0 m( Q5 C; |
- && typeof document.documentElement.clientWidth !=
: \$ D8 A1 K3 a8 t: N9 m! j, ` - 'undefined' && document.documentElement.clientWidth != 0)
& x* D5 _* o/ a$ `7 m. n - {3 F1 c. b8 p- Y4 q2 ]
- viewportwidth = document.documentElement.clientWidth,
1 V( Z, A1 t! F! L8 o" ]$ P8 n - viewportheight = document.documentElement.clientHeight) b3 o; Z$ m; J' l6 {8 s
- }
2 c" ], {8 c; M Y$ b3 k" ^ -
- ~2 b+ i$ m7 k- R; @ u0 ] - // older versions of IE& r/ J/ s3 H" i+ i, k$ W* m
-
$ P' P0 N9 b! U% c! ` - else
. ?! n# K$ B5 m/ E+ k - {; A7 R6 {. ?. x" i! Q
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,' \- @! G3 w7 x- ^" r. V2 \
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
. l) [5 j: p& ]# d. t; U - }+ F. q" J- _7 e
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');* z7 h8 ?* ^' t% X
- //-->( N6 v- Z2 s4 u$ _ a
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯* M! K e b: f5 F; ]1 X/ F# l& _
: Y9 H7 A7 m& q2 Y/ g! l
8 |8 S5 D- f5 M靘皞: Get viewport size (width and height) with javascript0 G; t/ ? l2 [5 T! b
; k; O' ]0 K; f+ O+ x
o! ~' o4 c" D5 f |
|