砍敺 media 2014-12-10 19:08 蝺刻摩 Z, _! x& Z! l: w
, W5 k1 S/ S5 s5 S餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具1 Y w) a* f0 Z8 B6 x& _
- <script type="text/javascript">
+ V/ _ \7 g6 X4 W% A - <!--: f. f8 K2 j6 X! s$ a- ~6 E. B( ^+ J
- ) @$ W, {5 x, P( Z) Z( E7 P3 ^
- var viewportwidth;" ~+ k' }6 e2 p* Z
- var viewportheight;: G/ h- K Q' J* i, p6 ?7 D; l
-
* H2 e, N4 a5 a - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight, A3 u. R. t, O; W3 _. t
-
! A* w+ b; a( w8 x0 b% Q6 C; r - if (typeof window.innerWidth != 'undefined')( [' k4 l" T8 ~, T
- {
2 [. U5 p: `1 L4 o - viewportwidth = window.innerWidth,6 Y' S8 _: _# U1 [6 @6 b! z
- viewportheight = window.innerHeight2 a# v1 A. R& K3 m
- }
# \4 N$ b f% X$ F7 L. I -
3 r' W! R. H0 V& ~ - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)) D; o* h+ i" P, @3 R6 g+ A" U
4 V. z: q, U6 W- else if (typeof document.documentElement != 'undefined'
2 v/ E$ A+ J7 w5 P% Z6 ^ - && typeof document.documentElement.clientWidth !=
( l, `4 o8 v" k2 h* ]7 P& w' J' e - 'undefined' && document.documentElement.clientWidth != 0)) ]$ F/ ?$ y B8 c) W8 n7 s3 a2 y
- {9 h7 s( K$ y" J, U( }& Q# L& a, a
- viewportwidth = document.documentElement.clientWidth,
9 O5 Q7 J* V3 t9 }( l - viewportheight = document.documentElement.clientHeight
- r# b7 y+ e5 I- V$ N: r5 q* H/ ]4 l, ] - }, V2 o* B, m6 q( f8 ?9 f/ w+ }7 \
- ! Z/ e. N& D& y& W0 U3 N L
- // older versions of IE
, H6 ~7 U T/ A+ k8 ?6 ^, y/ Y -
. ]- Y& q+ B! C! D& r4 h - else9 X+ Q/ d# ]! _4 f
- {
+ s! q. [1 x: T. A( H - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,% M4 X' N; Z3 o) h# D" g
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
& U+ @4 p- \- C, F - }$ b2 ]9 B- I; S8 y; W
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
( W- G6 B1 H0 A - //-->& n8 i2 Q$ j: L% d& A
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
8 H# M4 }% O( N( q) o: n/ {
* `2 J, Z5 y5 h) j
0 b6 \, I+ p" M" R$ r0 C7 V" o. `靘皞: Get viewport size (width and height) with javascript
2 r6 O# q. o0 B. h% y' } @9 ? Q7 O* B& E3 u2 ]0 S; ^
6 S* M9 f0 p6 i' ]2 } |
|