砍敺 media 2014-12-10 19:08 蝺刻摩
1 _: y' y- t# A. k7 W( j* a* F% p" m1 y. @; n
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
3 n* B& W- C( K, c! ~- <script type="text/javascript">6 F. ^# K/ f+ t9 t0 V+ j/ \
- <!--
5 n/ \* {9 U) _) K
# J, B7 K% W9 U7 w- var viewportwidth;! p" |7 F5 \. `6 i4 l
- var viewportheight;
7 U5 a" w9 t- e - * p, D9 X( A- P" W4 ?
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight4 u3 G( }0 L) Y5 N" g
- _! u- v8 F8 M7 I/ x! ^
- if (typeof window.innerWidth != 'undefined'); ?1 k, r, C/ Z$ F' R3 Z
- {7 Q) z$ E9 [" |: P% Q) j/ [
- viewportwidth = window.innerWidth,
: K7 ]: \5 I3 b2 a( \( q - viewportheight = window.innerHeight
: ^" M6 n0 s( x5 b) T - }" t5 F# `! h( N0 s' |( k- k$ J2 N, B
- 3 G% c/ s3 [7 j6 |
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
, S0 C+ l; n- K2 e6 G
9 K# t1 d! O/ J) J- else if (typeof document.documentElement != 'undefined'
- O/ |$ X4 m8 k2 C, T h - && typeof document.documentElement.clientWidth !=* B7 x; R' }! ]) n
- 'undefined' && document.documentElement.clientWidth != 0)4 k* I4 N8 v, ?! J- p' }
- {
/ y9 Z" c7 _4 |. Q5 S, l - viewportwidth = document.documentElement.clientWidth,) m$ {9 M5 Q8 V2 M( P/ z* ]
- viewportheight = document.documentElement.clientHeight
1 \9 z" L5 T0 q3 [: V( Q8 W7 W" j7 d - }
; z4 c" g6 }6 h8 F0 T! D: h+ C - . q/ ~, J0 {0 _) z
- // older versions of IE2 o0 f. h& t$ O9 x1 ]
-
2 M+ \9 _+ {, V4 Y Q! c& C4 h# l - else
. Y3 ]/ @8 U2 N& h$ J# E# C3 ^+ Z - {
2 Q- Y$ W5 _9 x2 m$ U; f - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
c( ^* I9 B1 B7 C8 `6 n - viewportheight = document.getElementsByTagName('body')[0].clientHeight x# `) A3 I4 V! K0 y
- }5 C P8 m& q. p+ {! h- |" Y
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
7 ^5 i1 v; Z5 T! b* q V' P. K - //-->
4 I* B' ~1 [! q) A! j - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
! Y, \, o4 A( A5 w+ E1 M
9 a/ Q1 L/ O: f
& \( ?) q f$ R& p g+ f5 k- h
靘皞: Get viewport size (width and height) with javascript
/ _7 m1 `2 p% ~9 }" ?5 K7 u% F8 u# G: V. ]. @" F; P
& t+ P' U% {8 I! f0 {
|
|