砍敺 media 2014-12-10 19:08 蝺刻摩 4 O9 @0 @) C2 E2 u) v
+ r9 I# N/ e8 J: W2 t
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具6 u2 M6 ^* J; f# e9 d% g( v
- <script type="text/javascript">: S# T" W) M5 v' u: T
- <!--
- ~- y- B5 C9 r. G8 M* x3 P; Z+ b - . h/ i& W7 V9 X$ T$ ~
- var viewportwidth;) B, P& \: l! D3 A. ?; y) S- P
- var viewportheight;
6 F8 y, J, K5 a: q& \1 O( ?1 j - , K$ U# U/ L- E# v) q$ p8 z
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight V2 u$ O- P, V. M, a4 R' W
- f0 b/ {, G6 T- D7 M
- if (typeof window.innerWidth != 'undefined')( @0 G6 V2 v- u: K/ f+ {0 R9 c7 s
- {' g0 w* ? N% X' m0 m
- viewportwidth = window.innerWidth," A) {3 G% Y! j* Z7 [& [
- viewportheight = window.innerHeight4 m( I s. }* _: m# B9 z4 g
- }
4 v6 q+ Q3 r6 h( K- T4 L -
3 m# p# F. T& F% \ - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document). i3 Z, j8 R5 Q1 R- q/ s) G
( W9 K7 N% C2 b: H" u& g6 R7 K+ H- else if (typeof document.documentElement != 'undefined'
8 A. h( {& v( d# h, f/ u; i - && typeof document.documentElement.clientWidth !=+ R( ~- R$ I/ A( A
- 'undefined' && document.documentElement.clientWidth != 0)
^3 G, [2 X- ] j - {0 k+ C/ u$ s, {9 p
- viewportwidth = document.documentElement.clientWidth,
' ]8 l' `3 O) m- U - viewportheight = document.documentElement.clientHeight; e; o1 W' e j. I9 E
- }9 p2 N4 h8 z9 K; w6 }/ y$ E
-
3 ~/ r1 r) R3 c/ _2 t: \ - // older versions of IE
* b; h4 J0 d: ? l, Q* e* ?+ g -
3 N8 c* i2 ?+ U! f - else
8 C) b2 U' x: D5 A+ k - {
$ Z7 R- j/ x) J. | - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
# U, e' v& _1 D8 m0 K - viewportheight = document.getElementsByTagName('body')[0].clientHeight
6 m5 v" ]$ o9 l' _5 ?7 Y - }' ^" F1 a3 ]5 H# e1 m E' k
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');! V) @0 j( j# l! L5 J
- //-->! s6 [; b0 e' C
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
$ p6 z. r# B% T% ]
, g8 k4 |, k4 N) V4 G
) _3 f9 `; x6 a$ Q* ~. P0 y靘皞: Get viewport size (width and height) with javascript
" w" F& v5 a+ p7 c. X0 V" P. U9 Z$ H5 O) T& [, i
8 _7 @! d2 s$ E' V$ B |
|