砍敺 media 2014-12-10 19:08 蝺刻摩
. I1 y/ e9 y( }$ v% L3 Y
" |5 z1 p: Q3 }8 ^2 W. \9 h餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
! T) v6 L' Z' f7 H# Q2 p4 a* {- <script type="text/javascript">
/ x& E' \& O- L, C$ F! u3 _ - <!--# W6 Z; @0 b6 x- X: U; N; q2 G
_3 t! r4 J+ Z9 y- var viewportwidth;7 p: o. c( C" u& n5 n6 G: _
- var viewportheight;
# ^4 j2 f+ `5 e3 O8 M. S5 l! ~) ` -
) V( A7 v @1 J4 j! G1 T - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
9 w j1 s5 s- w2 ^% k8 V' D! f - # i, K4 K4 y5 @9 j# P! E% Y
- if (typeof window.innerWidth != 'undefined')3 m1 {' z0 Z$ w
- {
* u1 n) D6 ]; w0 w( W+ ] - viewportwidth = window.innerWidth,
/ _; F9 f0 Q7 {- I - viewportheight = window.innerHeight
4 Z# b+ ~: R" C4 t, S8 x2 D - }
: `$ d- O0 ]2 C5 D* H - ( s% N/ v7 o8 w9 j7 u, `
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
( P! n3 X/ e: s$ M* p - ! O" y+ u# n& r9 S/ U1 j
- else if (typeof document.documentElement != 'undefined'
0 P" n- s; x9 p- r - && typeof document.documentElement.clientWidth !=+ U! }6 a W; i* m' V& R7 F6 B/ f
- 'undefined' && document.documentElement.clientWidth != 0)
0 q0 w, l G5 P. j - {& ?7 l5 l; S& v% t* |0 D w& U
- viewportwidth = document.documentElement.clientWidth,
& p. A8 C$ K2 ]3 ?+ R. M - viewportheight = document.documentElement.clientHeight
: Z1 N2 T+ N. P& _ - }7 O9 c+ h" R8 ]) y& J+ o
- - M+ A0 S9 `9 r J1 A( Z- \$ p
- // older versions of IE
: j; t8 S ^2 C; v- F5 z - , s" O, W) G1 x4 ]8 C' |
- else
# r* A; h2 _6 u% l - {5 Z& E; _) A6 s1 u
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
: {, ? T$ e4 W1 Y6 r4 C - viewportheight = document.getElementsByTagName('body')[0].clientHeight; c5 X, i, o# L: C. r- `2 M1 C6 J: i
- }
, F# {% A4 w4 X* @) F! t - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
- a& I7 o( {( |: R - //-->7 r0 I% C5 N$ Q. l
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯- t. D5 _7 J7 f6 N5 D0 u
, J5 C+ i) }, a2 S# ?) a
% @, O* C) f( L) I* t靘皞: Get viewport size (width and height) with javascript5 _- D# P+ A: T- q# B% Y
, H( |. x4 R. F% B2 b# e
% a$ e9 ~( j5 G( k& W: M
|
|