砍敺 media 2014-12-10 19:08 蝺刻摩
% O2 p- g2 k/ p+ S3 m1 q% J1 P8 R) I- G/ a$ @% X6 E
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
1 u7 l6 ^0 Y* E& K0 T s9 w+ \- <script type="text/javascript">
5 O: v1 F/ _, p3 ~2 J5 a - <!--7 {- w& `1 d6 u: [) [
6 r# k$ Y% a; ]4 U3 ]3 S- var viewportwidth;: F: H) L6 s$ N/ a% z1 p
- var viewportheight;
8 r& \; t) l6 M7 ?) i$ T6 G - . Z, S7 U; @) u& N
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
4 j4 r4 Z! D3 |/ I* i1 ?5 i3 _; d -
0 Q/ B( p% K/ S2 B - if (typeof window.innerWidth != 'undefined')& q7 J9 ]% ^* h3 I( U1 @5 U) t0 a+ |# ]
- {
1 y! X! Y" [/ \1 O3 S - viewportwidth = window.innerWidth,
1 k \+ Y4 [& d) B4 n - viewportheight = window.innerHeight& x1 L/ I% {4 W& Y% C
- }# w5 c: M9 H! \
-
. ^, ?+ _ L9 s6 W/ @ - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
4 F4 D; [, {1 y6 k- d) S - * h9 f- y# i5 z8 h( b! p1 u
- else if (typeof document.documentElement != 'undefined'7 P. T/ F" V4 Y5 j
- && typeof document.documentElement.clientWidth !=
* L: t, L) O+ a9 |" K( m0 R! ] - 'undefined' && document.documentElement.clientWidth != 0)$ ^; _( X2 t. E7 e @9 a
- {
/ B: A5 `8 z+ T8 Y - viewportwidth = document.documentElement.clientWidth,$ C1 ~8 {# w' k Y+ D
- viewportheight = document.documentElement.clientHeight
, s7 S8 h& r- c - }
$ E x6 _& }8 o N - & k; m+ j* ~3 ^3 r
- // older versions of IE
1 y) X7 e3 c- \ -
# t8 x5 s7 ]5 X% d9 N( U7 z; c - else
! Y+ v/ u; e. k K- r$ Y) ? - {. c, U+ {- ~6 S* \
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
9 V% ^8 h0 F+ v% Z& p2 P9 G3 a - viewportheight = document.getElementsByTagName('body')[0].clientHeight, G! e5 M5 e/ P% z1 }
- }1 I; H- L/ N+ Z$ P! P3 r% C
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');+ b, l$ P' R; B! d9 b, f
- //-->& @2 k( T+ a: F
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯8 U' |* t$ ^' t
: N& W5 E1 ~1 [4 B) T. [
7 d( @. D# _6 J$ Z' w! n靘皞: Get viewport size (width and height) with javascript$ K# E% S$ O+ w: @9 r5 [
: m, \( l p4 D, u
3 W" |0 X- j1 \$ i& ?" F |
|