砍敺 media 2014-12-10 19:08 蝺刻摩 ' X1 H3 |0 C0 f" R
/ ^2 O9 O; Q0 U: T# ~8 A% n餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具 g* T% @' B: j0 M6 y6 ?. M
- <script type="text/javascript">
0 [) X8 V- a7 d' S - <!--
0 \$ C5 w. e! c( V% C9 ]4 K# {9 n - ( g, c! u" _, s9 i; w7 r9 X
- var viewportwidth;+ z) k/ I' i, j6 W
- var viewportheight;
) S6 d* U( H$ k4 _9 d+ N- B - ( }# D% j) L3 i/ S$ e1 ]
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
& t$ T) {4 ]$ j+ O -
8 E+ x* s3 ?4 }, i - if (typeof window.innerWidth != 'undefined')
) ]( L7 `* \% [! v# g - {
u) _' {; k; q5 r - viewportwidth = window.innerWidth," j1 ]% W+ P3 y
- viewportheight = window.innerHeight4 F" J& G" h& ], W% Z, U1 D
- }) K9 |; {1 ~$ U; a# D+ }
- + d& h/ D6 x: Q. Q0 g `
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
* ]; C3 }/ ?' T- j - 1 M; x: p& V/ L
- else if (typeof document.documentElement != 'undefined', H2 G9 c2 C; w7 F$ P4 W# |- ~
- && typeof document.documentElement.clientWidth !=
& R8 P. w/ H- `1 l - 'undefined' && document.documentElement.clientWidth != 0)6 R6 i* K$ n3 E$ _) j+ y
- {3 D) e9 F G1 t0 S
- viewportwidth = document.documentElement.clientWidth,
5 e# s# `! F% w; h2 ] - viewportheight = document.documentElement.clientHeight
$ y! L7 A& g; _ - }
: H7 m' Z7 ~# ^/ ?& N D3 h/ X0 T) } -
# O2 g6 Q5 ?1 N2 T2 H$ H+ @ - // older versions of IE
% y& m+ p+ a3 X# c0 q - 7 Z$ i0 A, H. W2 r
- else0 T' J3 P6 m) d3 u& B
- {
7 ~3 Y9 }' X. T9 d3 d" U - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,: {4 V, F: {. N
- viewportheight = document.getElementsByTagName('body')[0].clientHeight+ {3 y1 v3 I4 |) R: F4 R
- }( C$ J' X! y0 x' L4 L0 ]- J, d
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');+ k, \8 }. }4 V0 G
- //-->
# g8 _+ I9 G* I) l* k6 R - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯- l+ ]+ O1 O/ ^4 A
4 C7 l( Q2 A# K1 Z2 L6 a. M
% B) u) h/ m8 ?$ f! r5 `
靘皞: Get viewport size (width and height) with javascript: I1 h+ n. f& [* ]5 C' }
/ A$ x1 ?8 x4 h; X2 X3 M5 ] z2 j: @9 A6 w+ Y+ m5 N' x
|
|