砍敺 media 2014-12-10 19:08 蝺刻摩 - H4 j# }4 h3 c v+ K: u$ y
5 F3 w' Q: ?2 {8 _' `餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
7 P3 k- n# P: ^, i7 X3 N- <script type="text/javascript">
$ _1 ]0 `7 \* A- w' T* F4 M - <!--) V% n1 y# R. O% W$ A6 v
* w+ E6 v# f' w6 a* m @- var viewportwidth;
" j3 U1 [ [/ B - var viewportheight;
% F2 d8 P3 [: i7 q! P" Z7 A - Y* \5 N% @% `" y8 s% f& i
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
7 D: w2 G# s( X( o* T - # }$ A4 A$ x2 t" C% r. ]5 k
- if (typeof window.innerWidth != 'undefined')
, p7 k+ x( ~8 ^% J: H - {
) k8 o' z: K& p: R3 P3 y - viewportwidth = window.innerWidth,
# C1 h7 h7 o& Z: H - viewportheight = window.innerHeight+ b {0 t% b9 A3 m
- }3 H: ^* g8 N7 g3 O7 ^) Z
-
5 ] T! P: Y/ b8 P - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)* P! a* {6 @" `% ?& Q9 G% b6 l
5 N8 S/ o+ F9 S9 V! h. E- else if (typeof document.documentElement != 'undefined'
! T9 f) L2 ?' Q$ G5 w) s - && typeof document.documentElement.clientWidth !=
. s0 P' N( n0 K - 'undefined' && document.documentElement.clientWidth != 0)
9 h& F1 A% @* [6 @6 U( H& Q - {
3 b9 B4 V/ A8 f. K4 S. j1 z. \2 K2 w - viewportwidth = document.documentElement.clientWidth,
' ? {0 W. _6 r; o1 s- _- e) r7 S - viewportheight = document.documentElement.clientHeight
/ _/ j, H) D% Q" v' m - }
7 V, z& ~& n4 E4 a+ I! t- C: c - : @7 ^7 r, _% F% v5 f0 Z8 F8 s
- // older versions of IE
' \& y7 T% _7 I# F$ \! E( w' Q - ) G0 ~# G6 _' H8 c/ y5 C
- else: z" r0 w* t! y9 [4 o' j$ w
- {+ R s. B9 S: n/ l/ A
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,/ W8 G, D, A/ E
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
) ^( k5 D" [ h4 v4 X, a. I - }
0 D1 p1 r" X" ~% }* r - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
6 z1 v6 ~ u" J7 N8 t - //-->* P9 t3 s& R/ p; h! L
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯, w9 F/ |7 z4 V( D3 R
% s* S% y+ o9 ]4 e8 M* s6 h0 r1 N
4 E0 ]$ l5 x" S- D靘皞: Get viewport size (width and height) with javascript2 _; `# @! U7 M, u N; Y
& ~5 t: c; @9 S6 z4 P) s
9 b$ Y. }3 T: D# C* a |
|