砍敺 media 2014-12-10 19:08 蝺刻摩 * [ h& n5 D( E+ ]9 N& s
5 C( O! O' c" t/ ~" D餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
- m+ T/ o' L4 t; Z7 y0 Q0 ^) ~5 e- <script type="text/javascript">
# t+ `- b0 m1 n& Y% v - <!--8 g/ C* d" ~/ \$ V3 T2 j
9 |, ~* F) f3 i0 x: z- var viewportwidth;
2 H( m5 H" F) ?: q' V' c5 y - var viewportheight;
8 Z l5 l5 o# _# e -
" L) o: X! \; E' a! O8 B - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight8 Y4 n. i' V+ `
- : F4 F0 r g5 S! q' B- h* n
- if (typeof window.innerWidth != 'undefined')+ T' p% ^, s& `4 a
- {( h3 o' c! ~% R) p
- viewportwidth = window.innerWidth,
6 ]- o& H& k! Z* L) B- v2 s - viewportheight = window.innerHeight
9 X V% V& F5 R. | - }+ N+ e1 i" j$ p# v3 I R( x$ \
-
/ b! S, |# G8 c6 i! b+ f. m - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)5 h. \( U% M6 y( \1 n$ B
# r6 F5 n; Z" }' y6 o( x3 b- else if (typeof document.documentElement != 'undefined'. S; M# B# P' Q1 Z- Q$ x
- && typeof document.documentElement.clientWidth !=; Z) \) u0 M% G8 a
- 'undefined' && document.documentElement.clientWidth != 0)8 D8 o W$ v2 k
- {
; y$ X! D+ h( C9 w" ^4 w/ l% w P - viewportwidth = document.documentElement.clientWidth,+ R8 t1 |5 t2 E+ w! q
- viewportheight = document.documentElement.clientHeight) W0 b. @) |" L7 T" }+ o
- }
4 s5 e* Y0 c' ^3 K2 i2 H8 [ - ; ~2 g' F% J% h( [" A
- // older versions of IE
( _ {" M( E d% F9 H7 H' X -
; K2 H2 M# g1 }1 D& \& L/ u# _9 S - else, R5 v2 g# J6 `3 T( E K. Y
- {$ _4 C% f9 a# \7 L9 O
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,/ G4 }' a0 N# r Z2 F6 O% J
- viewportheight = document.getElementsByTagName('body')[0].clientHeight. u/ N/ R. T& j1 n* A
- }
, o W4 P' O. z# a H' }. K - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
) V/ {; j4 x- J" C3 y - //-->
0 x# C+ _( f* t) S/ ~ - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯4 O: h* r% R6 p. L' c! j4 K
: ~# _) H4 T1 ]9 W- \& w- X
0 K1 q( s" D3 |1 b1 Y
靘皞: Get viewport size (width and height) with javascript6 r; } I3 y$ D0 m) E% _7 y9 X
$ w" r9 S. Q( f" C s4 Y% X
5 r* n, B; ?3 _% s1 m. c |
|