砍敺 media 2014-12-10 19:08 蝺刻摩
- Y3 i$ Q) V1 L s1 R a
. L+ u7 A# x+ Q1 j9 B) z餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
* N) q' s$ |0 q2 }! t- e- u; \- <script type="text/javascript">* F4 C0 x, O# p' i* c
- <!--* }8 Z2 J' p# A( e) z
9 ~4 [, t, p; k) @: m- var viewportwidth;
, h. B X( U {0 [- m9 B3 M% N# J8 S - var viewportheight;5 d& r( d+ w2 U; u9 y
- ' b$ h) s9 I1 A
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight) b0 \" e( ]/ V" H; }& R
- : M6 Q4 Q: ]7 t: w- {" z% m6 W, P
- if (typeof window.innerWidth != 'undefined')
. u" n2 [8 L, @/ Y: ` - {
/ l2 B5 O& @* ] - viewportwidth = window.innerWidth,3 M4 i$ G. i" V
- viewportheight = window.innerHeight
- X1 g( p4 @: E" U6 y/ }" V - }+ ?; K* q1 E8 c$ H
-
5 b: y# r0 o& i1 _( o8 d - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)( r6 ~5 I+ k' \1 y/ O3 J; q
. c5 ?) W# W ?# V, U8 o$ T$ p h- else if (typeof document.documentElement != 'undefined'
3 e: W+ v0 i" T" o7 D% v) n4 f - && typeof document.documentElement.clientWidth !=
4 A& e0 N( |2 E" q% o1 ] - 'undefined' && document.documentElement.clientWidth != 0)/ m# G( K; E+ I- _/ ?
- {
5 i, c0 b+ b6 l0 v/ ], W; @ - viewportwidth = document.documentElement.clientWidth,
) n* ~" y/ \' A, a- m$ ~- ~4 d3 t - viewportheight = document.documentElement.clientHeight" a/ m/ P r- Y' p: Q0 j) d# U
- }
- U0 Z" Y0 O* h9 T" t1 o - 3 n: } A! D) H- |, u* H
- // older versions of IE: J' T G/ Q4 W7 }
-
0 W8 T$ V8 [. Y" w: ^ - else" v! L- U7 [/ l# A6 c( H( q+ s
- {
4 s" B( q0 W# J5 ` - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
9 C, ^1 \8 C: S% @7 l - viewportheight = document.getElementsByTagName('body')[0].clientHeight+ s) e, b9 n! r0 K" T
- }
: D1 J( u4 c4 p - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');; x$ w% C M! L
- //-->
" k k, e: |+ D0 J% I - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
' V: O0 L- N7 }4 ]
8 n- P1 Y! s) N
/ i6 t. s* V( _; p0 J
靘皞: Get viewport size (width and height) with javascript& f5 y8 i) k/ N ]+ F) ^+ o
2 b) \% _4 x) t0 b% {% f
) p6 C) |& U6 [7 t
|
|