砍敺 media 2014-12-10 19:08 蝺刻摩 7 m0 ]/ o9 T& U" m: q! T
7 l* E/ S/ O/ E8 Y! `' E6 R餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
+ f7 e5 ^9 p" X W. O- <script type="text/javascript">, ^5 W* \/ I$ `' R$ @
- <!--/ O0 i/ }7 _( F) Q ?" P R I- v% p
) A) Y+ v, s: ]7 z9 J- }- var viewportwidth;
9 r3 D2 u! t7 d - var viewportheight;- V& }" c2 ?% w. X' l- t) ~9 o
-
! \ K9 {/ J" [- |0 m9 f: }' d - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight& t9 O" W+ ^ a
-
P/ F% [, T. p& M- L1 B1 O, x - if (typeof window.innerWidth != 'undefined'), j. ^4 ~/ E0 q% J" `( L- J: r. x
- {
" i- X1 j4 I: j& d, n% a% ^ - viewportwidth = window.innerWidth,& h' ?, s3 f- _" Y8 H+ l
- viewportheight = window.innerHeight
4 W5 H r% b+ v. E) h! N' [% Z - }
8 \- K% t5 E$ V; N' c: f# w, A -
3 _/ y' S% @ t' a) X* l - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)) ^ M: s: w3 J( W5 E A
- & J/ c: n2 k& j3 u8 D) i
- else if (typeof document.documentElement != 'undefined'
# w& U# Q9 I: V* v, J+ i - && typeof document.documentElement.clientWidth !=
7 {" G4 w R, D# j - 'undefined' && document.documentElement.clientWidth != 0)2 n* n! ~8 o5 M. D
- {% z8 F0 _3 b; B* X; ?2 [+ ^* {
- viewportwidth = document.documentElement.clientWidth,! G8 F% I8 T( i1 b% U9 J- t! a
- viewportheight = document.documentElement.clientHeight
0 `# i; L0 f8 h: a }2 a - }# q8 ~! B/ I: p# `) U& c
- 4 \4 O" f3 p! o3 E1 g+ v. ]
- // older versions of IE$ [# _& ]5 Y c1 q8 {7 ]7 |9 R
-
$ t6 p. ? U q T! _ - else
4 N$ w# F9 D. F; A" z - {0 f! d9 ]% G- |& N1 d" {* z2 x. \
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
5 _! |# n( a! }6 T& e$ ~! H s% \ - viewportheight = document.getElementsByTagName('body')[0].clientHeight
+ U c3 S' u: Y - }
. C% f! d, C3 V, [3 e - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
: m' S% C' y: W+ {7 Z* g% p8 Y. w - //-->7 l; `7 {! O1 @& n3 @" T; x
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯: k7 ]7 t/ r& `8 Z. N
! z. P* u a* M: O2 C7 P
/ j7 d+ W, F- |4 B5 {. r靘皞: Get viewport size (width and height) with javascript! i$ }9 [8 {) P8 s3 f
7 \2 Z$ I3 I1 H7 }
\. `" }+ o: o* J& b' L
|
|