砍敺 media 2014-12-10 19:08 蝺刻摩 : e- V7 a% t' K
# I/ B% i8 o& i) _餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具5 w: A6 v8 e0 q3 I/ J
- <script type="text/javascript">
0 S R2 [. X) R6 ^ - <!--! W. `! w2 R6 Y. [0 x7 g5 H) c" e
- l# E5 `0 J- ]- var viewportwidth;. Z8 V3 `; R3 p, ]0 M" }) R
- var viewportheight;
4 u) P" d8 c! Z5 x9 f -
% b7 ]: Q7 }( _; O3 z - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
( w7 G/ t$ Z/ _1 ?+ W' d( o - 4 \0 j& ^* j% ?. r' ^" C8 h& I+ m; Z
- if (typeof window.innerWidth != 'undefined')& o1 a8 j0 T% C7 s5 k) V) x
- {$ h/ W/ w% I5 W4 j, m9 s
- viewportwidth = window.innerWidth,9 i$ Y6 w% Z6 r' Y; I
- viewportheight = window.innerHeight
4 `' O [8 l0 I* C$ [5 B% Y - }
' k/ ? O3 r6 A: Q, ?1 R - ; e) e) S+ p" v) e0 k1 M3 \
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
A- A/ A4 ~% F9 H8 c+ m. L- Z) P
, r: b3 }$ z: W" R- else if (typeof document.documentElement != 'undefined'
7 I# | @+ @& @1 j% Y1 Y - && typeof document.documentElement.clientWidth !=6 N, S* s7 e) ~) G9 k% h( J$ T
- 'undefined' && document.documentElement.clientWidth != 0)
3 W$ b3 R1 z# J4 I G9 a - {& X7 t6 _5 w3 Y0 y5 K7 w/ _& J1 U
- viewportwidth = document.documentElement.clientWidth,
, y- D2 ^+ n! T% v - viewportheight = document.documentElement.clientHeight
! z' n& p+ f3 Q1 g2 `+ ~ - }2 @ {- W! L" T% p7 I
-
1 L6 j; \7 s$ ~& K - // older versions of IE' \7 _, c a+ d1 \* j- V
- ) ^. W* S/ }" N
- else! O6 U" h- A. C8 l
- {+ @5 l/ ?) G1 R' v0 d
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
! @/ J8 v4 i: F - viewportheight = document.getElementsByTagName('body')[0].clientHeight0 Y% g4 O6 N% H2 K: z
- }
8 d# p1 x: {4 O7 I- N, v; d - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
5 f g( W+ h6 [ P5 j - //-->; A4 y8 z8 W: f. P. _
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯1 e. ^3 Y% w; u7 D
9 e0 k" c0 i- B2 a- {8 U1 x6 o
5 |3 C7 c# }& v, k( L7 c
靘皞: Get viewport size (width and height) with javascript
& p5 H7 @& n7 d) Z, C- y
7 c. Z/ ?* }" ~
% u; K+ \" X! H1 }9 n! J |
|