砍敺 media 2014-12-10 19:08 蝺刻摩 8 t; x- ~6 O5 m, j" i
% z3 E( h6 k* u( w( `
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具) _7 S% G6 r8 t
- <script type="text/javascript">
; x9 J# E: Q, c" b) V5 [% d% k5 b$ O - <!--0 S8 L- j' H( ?# S" K! F+ K
- : v! E$ p# U4 x! k8 K/ ~
- var viewportwidth;
/ r- A# Y* I5 D: n - var viewportheight;
- ~7 M9 Q6 p9 D+ w8 p - % o4 h& ^ V' T" |9 N# t
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
8 n" Y: Q3 O& y$ m( P2 b -
1 N% J0 c6 S H5 p5 j. c8 ?% l- ~ - if (typeof window.innerWidth != 'undefined')
( C, |7 ]. S; P" P - {2 P( A" n, }1 P( v& }* x& }* i
- viewportwidth = window.innerWidth,4 \( O$ z! J1 L' W) Z
- viewportheight = window.innerHeight1 Z/ c. p3 u3 F
- }
& D! w0 v0 ]2 B: D% n5 |# |+ U -
% m. T! U( y ?9 d. E% G$ i' d - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)8 l* L( f0 V8 T& I# c3 [/ e* f/ H2 [
- * X: T, V+ B- ~5 L
- else if (typeof document.documentElement != 'undefined'
' u V# R1 Q% ^4 [. m; h& k4 U - && typeof document.documentElement.clientWidth !=
h& h; M) B2 q9 B: q2 n# ?9 z - 'undefined' && document.documentElement.clientWidth != 0)& F- ~3 z1 Q+ \* m! h9 \2 o
- {7 c+ d( }5 e9 B7 {
- viewportwidth = document.documentElement.clientWidth,
( V: O( B3 i: C# w& o4 A - viewportheight = document.documentElement.clientHeight0 w# _* {( `# ~
- }/ }* ]/ n2 J S2 M
- 5 u. H' i7 l5 d, c8 i6 l8 @
- // older versions of IE
) Q- F: B+ e) r* }1 o -
& c5 m5 s/ R* Y5 _3 o - else( U& Q/ }, S' f9 b' d
- {
9 M9 q0 u3 `+ W+ ?% e& M; V6 c9 N - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
/ D' v, J8 Q; U7 o( C# L0 S. f A - viewportheight = document.getElementsByTagName('body')[0].clientHeight
( f9 v5 t: X" e/ t- v' j0 M - }3 W2 e6 y$ [8 V/ {6 Z
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
6 m* S5 z! Y. s8 k* l3 N& S - //-->" R5 A/ }0 X$ u# A! B: Z
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
9 j$ r- f) L" R
7 {5 U' D5 {6 D# j7 l9 S4 r: Q2 g4 ?9 R% y
靘皞: Get viewport size (width and height) with javascript
# X% g/ d, ?' g2 }
6 B/ r. J, \6 v2 j4 W
# g& d" w9 U# X |
|