砍敺 media 2014-12-10 19:08 蝺刻摩 0 K" i( Y, |, d- t& {. N
* ~/ R& E8 P/ {, p \) `( Z h
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具! R' g0 E7 j# \1 ]6 @$ d
- <script type="text/javascript">
7 l! v g& B6 r$ m, G7 y1 _ - <!--
. R' n# l1 W) u" q4 h - + E4 r; {* a2 {- b
- var viewportwidth;
8 r& o' b( W2 y+ ` - var viewportheight;
" P# U3 G8 \5 W6 `. }& \! s -
% B: n1 e8 x; x3 O+ s" Q x- Q. _ - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
" [7 A' t' r( q - 4 a/ M5 t' D* ?0 ~
- if (typeof window.innerWidth != 'undefined')
* X% k2 x- x% b# F9 D - {! I8 H' Z' K" b" Z3 G! C- F
- viewportwidth = window.innerWidth,+ @; }1 o" e4 U! s8 s$ L( ^
- viewportheight = window.innerHeight
" L; J2 B' E0 U) l, m; r5 _ - }
) ?5 X1 P9 U" `# O8 M -
+ T8 o! S: P6 c1 z; ^ - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)- J7 r9 e3 V1 s1 L
% }9 r# H1 r, y) C/ J7 A- else if (typeof document.documentElement != 'undefined', D5 e& l1 s# f! w G$ ]) y
- && typeof document.documentElement.clientWidth !=
5 E5 r, X) | G- w4 m$ }' ^" N - 'undefined' && document.documentElement.clientWidth != 0)* F( c2 T! b6 q; c9 k" k
- {& o" k2 I& E, S
- viewportwidth = document.documentElement.clientWidth,! N* h& U" b! \( K6 F
- viewportheight = document.documentElement.clientHeight6 G, D$ c0 k5 I. P7 F6 R$ R
- }7 [- `0 Z5 x( b$ ^. f
- 2 r& K1 B9 X e e
- // older versions of IE# |- `0 T5 z1 m! J3 H" N. `& f
-
* @5 |8 j" D; w, p' C$ {/ y6 A - else I s* J0 u) ^$ ] l3 B; L" G& a
- {" \' I/ r$ J0 L m2 s& x F
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
- x9 D) ^( ^9 o) n$ K - viewportheight = document.getElementsByTagName('body')[0].clientHeight* e# q% G4 U2 U( R$ X; R
- }
$ K( y% o: c0 h6 X - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
8 C' ]3 h/ g2 _! X - //-->
5 B Z: r* _4 p, s3 d - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
8 B3 ^! ?4 `6 U: Z9 Y
7 n7 I6 @; w) l. e" \# \4 J. ^/ K$ {
& X, X3 ?- e/ t" }) i
靘皞: Get viewport size (width and height) with javascript% d/ Q1 q7 b4 X( ?
t6 b6 W% O5 ?
. B& J8 G9 U! e$ b. X8 v
|
|