砍敺 media 2014-12-10 19:08 蝺刻摩
5 S$ I. @; E' k f1 y( @9 g# t; n
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具" o( P: @! a& ]* D8 t: Z
- <script type="text/javascript">+ r1 f3 N6 ^* V, I
- <!--7 H6 _) F( g: w/ u5 l3 X9 a
b3 w9 z0 M" _- var viewportwidth;
; Z1 A, B, d0 d( |9 a I - var viewportheight;
# A$ m8 @* d( Q( V - # x! R% q7 G! b
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
, E! p8 e: i# x. _0 @: M; Y, ` - + y9 e2 p* K0 P' Y9 a }+ L
- if (typeof window.innerWidth != 'undefined')% K6 j# k0 s: V0 y# C" K
- {
0 h" r( J2 K1 R& P4 m& t; O - viewportwidth = window.innerWidth,
/ `4 o: r0 y/ ^; A& c* A9 _7 O7 X2 x - viewportheight = window.innerHeight
/ a( O. X& w# M1 m. O- \2 i - }
, c$ k, i P/ S( O9 D0 s -
2 d, C. `, e$ Z r" a* _" V - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
0 g; x8 k# u0 |7 R$ R6 j
% | T2 L/ s% O* n- else if (typeof document.documentElement != 'undefined'
. c% M9 b1 z7 B - && typeof document.documentElement.clientWidth !=+ [/ e5 g9 Y2 \* j9 e
- 'undefined' && document.documentElement.clientWidth != 0)
" W% y- d0 T/ m, {1 V& ]% g. ^ - {, C# P' P9 \+ t; J; J: s9 ~: a
- viewportwidth = document.documentElement.clientWidth,
/ u. b4 H# O, Z& u6 I - viewportheight = document.documentElement.clientHeight$ @' ^6 Z6 h% g" @2 i/ h
- }! c% [( y6 z9 K* q
-
5 c. X0 F. G0 b9 q: U" y+ x, q - // older versions of IE
! {& B9 g( o0 X8 M -
/ Y3 ] d* U7 e# M H5 V - else( R, F1 B: ]+ |! r- y. S @. M/ S. ~
- {
; K7 M% n- n) l% j& G! C" s1 X" J5 ~ - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
, A& H; U% ~& p6 q - viewportheight = document.getElementsByTagName('body')[0].clientHeight
' G% d% g y" N- m- z- x - }
9 z- D' U' ~; z" ~8 q, m - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');; n) f0 f7 w, B) n# e) U: f
- //-->$ i' q5 W" X7 u [0 M7 G
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯6 Z! E: X z) P3 a) N# G
! F1 V) o: M! b+ z
7 i' s' {! K& {8 J
靘皞: Get viewport size (width and height) with javascript
1 Y5 ^- k; ~/ A8 L$ n) U% \+ f. r' a
( e/ y2 v. I' t+ {
7 n5 Y' R& `& I6 n3 E |
|