砍敺 media 2014-12-10 19:08 蝺刻摩
/ y0 p" T' @5 U! r# q, y& x' a; N: X" _
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具, \% R: Q) {$ a, c2 M3 h% ^
- <script type="text/javascript">
4 s& ?# m+ S8 J/ [; D# x - <!--( `+ v4 U; I0 h- Q. Z" C( f
8 B) `& k- t5 X) v* l0 D! z- var viewportwidth;; Z- @" W9 P9 p" ~/ r3 z
- var viewportheight;
B. P4 ?5 |% b" r2 n! @! [ -
! z+ i1 r2 }6 `2 T$ d- u; M6 q - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight+ E: b; M+ {3 h6 `& U
- / b3 h4 |: |& ~$ N% W
- if (typeof window.innerWidth != 'undefined')
9 a7 C3 m' f; k* s: b. J - {- \1 R0 x$ Y8 D
- viewportwidth = window.innerWidth,
( C5 x! r. P3 O( ?/ _4 Q2 K - viewportheight = window.innerHeight
% p% u* g/ q; ~- ` - }, R5 b. N8 C" {, m7 Q' p. Y/ w; c y
- , \5 u0 L4 z$ e) j
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
y2 k# h* K4 |# c; f( H3 `# P
/ C: P0 M/ b# Z1 X- else if (typeof document.documentElement != 'undefined'
$ l. L2 i0 F* S2 G5 o6 v8 i - && typeof document.documentElement.clientWidth !=$ S3 v9 Q }& g
- 'undefined' && document.documentElement.clientWidth != 0) m8 W* M5 X" s. g) S
- {
% ]: N, z z# d3 m2 B+ u: j4 c - viewportwidth = document.documentElement.clientWidth,
7 p& C8 h* ]; y, \$ E! a - viewportheight = document.documentElement.clientHeight$ o8 u. X- y1 w/ W
- }
1 c. M- ^/ u% f- L T1 A4 @4 c - 4 F4 M0 h0 |" s1 C; A& E3 d
- // older versions of IE
3 r% P: B# l& |& ^) R$ ^ - 0 b# M3 H6 z: q7 W
- else, e; M3 @ ?3 K: \
- {
4 w* B8 [3 o9 M8 u - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
+ e& L9 K2 w; ^, a - viewportheight = document.getElementsByTagName('body')[0].clientHeight
+ ^; Z. f) |3 m, {5 m2 X - }4 w1 L8 d' U9 i' E5 s
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
7 [4 M; m" G4 y4 d, V0 G - //-->2 X% D7 v9 c0 q4 j
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯" h- Q& p$ w" E h% a
) `' ^9 K7 ]( G( M9 E
7 J/ D- U6 D8 y3 w% |
靘皞: Get viewport size (width and height) with javascript% O0 ^" J8 X) e6 x0 l
8 ~ B% O0 _+ v, s$ d( e& p
/ U, i# `2 V; v) u# p' _
|
|