砍敺 media 2014-12-10 19:08 蝺刻摩 " }+ l2 j! ~% x) ]
7 Y+ s, W7 Q0 J' X1 }0 E) u! L2 A餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具( F f2 A+ C' \3 F! f
- <script type="text/javascript">
* g( ]7 e& b! j' O2 } - <!--0 ?, a! K$ Z+ @/ O3 v) Z" v5 t
5 _3 @ X8 N+ `4 k4 q- var viewportwidth;# x6 \2 V5 O- c( E% D; o
- var viewportheight;
7 `) ^+ F# l( b6 n D/ j2 H -
- H5 _- e! X% Y9 ~0 L - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight+ u* ^: N) [$ l# e2 n5 V, S
-
, `! B, ~0 u, N Z - if (typeof window.innerWidth != 'undefined')
( f/ v3 o8 C' W4 F, Y# o' @! y - {# V# y/ a+ ?+ H
- viewportwidth = window.innerWidth,
$ \7 u( D% {. ?7 P - viewportheight = window.innerHeight' E: k" N; y; A& ?) D; K! ?
- }
! o3 @& |5 O) n/ f2 P3 O - * I) Q) J- _+ d" }1 e" R
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)5 a) A4 w( k$ ~) |. W
3 [4 t: j8 J& S- else if (typeof document.documentElement != 'undefined'
( z- j- l2 z+ p& M/ `* n- i, m - && typeof document.documentElement.clientWidth !=
/ J$ Z+ P! e: _) E3 d9 \ - 'undefined' && document.documentElement.clientWidth != 0)
3 c2 q. g2 _& N - {7 S% S5 S- |/ F3 K' C
- viewportwidth = document.documentElement.clientWidth,( P1 ^! z9 S3 M/ h# `/ B& G/ t
- viewportheight = document.documentElement.clientHeight
M! w% ~8 B/ n+ @! A/ S% p% W - }3 S7 U" K/ A% u8 }
-
- \* ?; O$ D7 h4 k" _ - // older versions of IE
( B' k1 d6 n1 u4 f3 j9 ^0 |, P - _8 x. G, K/ k# J: }. T( P
- else# w E. p; x# ], k& N8 {7 D2 D
- {5 v6 v: f2 Z8 m8 z
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
+ @3 n9 p3 `' r( Y5 A - viewportheight = document.getElementsByTagName('body')[0].clientHeight! H' Z7 J# _3 u
- }
# U6 b7 i" p8 J" i% ^* @ - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
9 E% N' k) A* S% @ q" v - //-->
* ]# A: {- n. ^- h! i9 U - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
6 l. a( y3 T" O* i
( o }& {3 n# P4 \
! ~8 B; _* ~1 j+ U
靘皞: Get viewport size (width and height) with javascript4 y) i8 d1 x+ R: y" a. q9 J
% Y9 ` G D u2 J9 M0 B' w
7 O' K* E$ |, _# F7 B) h9 x R |
|