砍敺 media 2014-12-10 19:08 蝺刻摩 5 Q* ?- S! _; c/ O6 G1 S
% N3 }, \) Z# c4 D# a7 O+ @; J
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
/ r _$ `# R3 A! N! R- <script type="text/javascript">" n/ j' `% ]6 Q, a& L @
- <!-- w+ c% f: E# w, {+ h* r5 `) w5 c
, U0 @5 ]( ~& |3 @+ A+ }- var viewportwidth;
( C7 {( d6 @8 S8 \: [ - var viewportheight;1 ]# F+ F/ G$ D* C7 C
- + Q9 @* L) E! Q& c/ R( T
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
5 j6 N/ m, h' W, c$ M - ' F- N. n$ Q# S" V0 F$ o$ [
- if (typeof window.innerWidth != 'undefined')0 y; R( _2 d1 |$ c- X
- {
# P# B4 h# C2 j5 L - viewportwidth = window.innerWidth,- _, o# Y9 D6 Z; F7 L' [& Z
- viewportheight = window.innerHeight
, m4 W7 |8 X3 I6 I- { - }
7 _' i9 Z6 F$ v* S4 j0 s, k -
4 r1 U- `4 B/ |1 @2 b" ]! ?6 s - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)* j K3 U0 a P, G/ p( o3 w7 T- h
}: T: U0 c5 w& `6 Y9 K0 T+ ]- else if (typeof document.documentElement != 'undefined'' M0 `! C$ C6 t% l
- && typeof document.documentElement.clientWidth !=
* h: x8 K/ _' w+ c9 j- G - 'undefined' && document.documentElement.clientWidth != 0)
4 R0 s f9 o& ^0 \% n - {
5 b: u4 }6 \; S; B9 b6 f7 w( i - viewportwidth = document.documentElement.clientWidth,. m: K) N* w }, A
- viewportheight = document.documentElement.clientHeight2 [3 Z( N( {! }( _- X
- }
+ B a$ {1 d- \$ P! I8 D, n9 Q6 ] -
, [7 R O, ~, _7 |. @' `7 s - // older versions of IE
2 T; H1 R" V, L$ N - % |. h) K: e& r, y3 A
- else$ P! ~0 z/ i' f9 K6 o) f- D
- {: K* U/ v# M) V' Y
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
- u" m. V, X0 }' O% [! V - viewportheight = document.getElementsByTagName('body')[0].clientHeight
; D/ W: ~4 d0 F5 j: y3 E - }
: Z7 {6 U* [/ ^: ~$ a* | - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
) D* P! h E2 V" J U - //-->+ e+ G& t3 t: y* t. p& y4 m
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯3 I( u2 w& C9 Q* D# K
9 B% z/ A* _1 \5 ~" n0 W) p
s @' U( ]2 N" }8 m8 a靘皞: Get viewport size (width and height) with javascript+ J+ z) ]: b6 V: ` ~" N5 O
# Z3 t. [' P# d
$ ^" ^) e# k) D# ]3 I6 a7 ] |
|