砍敺 media 2014-12-10 19:08 蝺刻摩 4 x3 k" V$ l) N; d0 j
$ L, \+ X& q0 l$ @6 s3 T7 F
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
9 o2 R& t. E( N1 X( `- <script type="text/javascript">) F3 Y6 M( ~1 b5 \; |
- <!--
, B$ M9 h7 [/ M% Q
; c) C S$ L+ A- var viewportwidth;
; D2 c6 p$ L* N: q+ l: L - var viewportheight;
$ H7 O; b% j0 ^3 [! @ -
" s; R! a S5 n3 Y% F, K - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight+ C k$ e. }0 e# n, a! q
-
* r" Z* ~1 C g7 F/ c% F' {3 n. G: Q - if (typeof window.innerWidth != 'undefined'); T% S4 s! h& f7 p: ^( p
- {# @( L6 `% [9 Z
- viewportwidth = window.innerWidth,$ v; M$ j8 \- {' V7 ^
- viewportheight = window.innerHeight
$ z n! I! _ J0 p' c9 L u8 e" K - }. o1 o# t+ K. K
- # A; \( c1 n7 @( { m! ]
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
% f; ^5 v0 s5 Q4 ~ h. S+ N. p* @" G0 r
* M8 X8 o$ O7 L( j& `( C! b- else if (typeof document.documentElement != 'undefined'# K' N: Q8 ^! F4 j
- && typeof document.documentElement.clientWidth !=
/ H7 R& b7 f( h7 M - 'undefined' && document.documentElement.clientWidth != 0). q5 ?2 v" g! G0 F# O& H
- {
' y8 `5 W: p2 I8 p. H: T5 w2 } - viewportwidth = document.documentElement.clientWidth,8 W# Y! n8 ~" k0 Q
- viewportheight = document.documentElement.clientHeight4 K$ f7 g- p" W% L
- }
4 z/ \$ @* t( J2 h( ?' j' k -
' k3 E- V& R4 e& e! l0 m1 m - // older versions of IE
v2 A) ]6 o `0 J -
8 U/ y4 q) t# i% E1 o+ g; `. P" a! E - else# X- T& ~" B6 g5 @
- {
) F# D2 q3 c' l9 m" Z - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
( t, O% e2 v4 T: ] - viewportheight = document.getElementsByTagName('body')[0].clientHeight
/ `! v6 [$ K; m4 M: S - }3 o7 n z+ i% _0 k" B
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');6 b% q" M$ g' O
- //-->
" I, d8 N; `$ K; ^3 K. \ - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯, Z, q0 m8 \( d1 f
! X. I! e/ r9 J% N# o% F' K1 W
5 K/ o/ J% o, f靘皞: Get viewport size (width and height) with javascript0 |( }/ f$ b+ y& k6 r7 n" n
9 ]4 `1 G! H' d3 V7 s' \6 g* r
9 \8 s1 p+ w, F5 w. ` |
|