砍敺 media 2014-12-10 19:08 蝺刻摩 9 X/ p; Y, \- z7 p% \& z* h9 I
; t, C* |4 _ k1 j餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具# n$ h, X. g& C/ g$ }
- <script type="text/javascript">3 n8 j7 T5 G/ O# J: ?
- <!--
/ b+ }+ s* @' t! `: r - 3 y, Q/ ^. m+ o
- var viewportwidth;
( ^. d( r7 c( }, E9 K* ~ - var viewportheight; I* Q" \) m* Q7 Z/ N# B
- 3 q3 k/ l& Z( i7 Y' V+ E* c: Q" }
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight$ X3 D+ G/ d( ]. X9 H/ Q! B
- # f* V) C/ a5 `8 y* B) S. A
- if (typeof window.innerWidth != 'undefined')
3 m4 J4 |0 m% X - {
( c8 @% X0 h l$ s& V! A - viewportwidth = window.innerWidth,
! S7 ~9 c" H5 e1 t% m! D% o7 k - viewportheight = window.innerHeight
7 R# U0 W: o+ i0 G" l" B$ }; h - }& Z9 f$ J3 ]4 J+ ?
- / `+ n& ^7 s: A4 `0 B
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)( y2 o, C4 A/ i' R2 B$ Y' Z8 Y! X
5 O% m& v6 L& ~# k6 P6 `! F- else if (typeof document.documentElement != 'undefined'
) m$ `: X1 y! N9 b) J9 [* R( y: y0 z - && typeof document.documentElement.clientWidth !=9 y1 V) [ H6 J
- 'undefined' && document.documentElement.clientWidth != 0)
7 o) q8 v9 `2 H, }. \2 T - {# z+ G" J# h& q6 t! s1 N6 a8 N
- viewportwidth = document.documentElement.clientWidth,4 l$ d/ h' V* J5 h0 H" s
- viewportheight = document.documentElement.clientHeight
* L" ?; l# v3 `6 z- R i1 a - }
, P# t$ z& ]2 x* H -
! B& @2 j4 m9 F - // older versions of IE6 F U& n' Y& K+ v* Y
-
. g) X7 d n7 Y, l9 G" _ - else
0 p/ f$ l! \* b9 n* `6 _. |1 Q4 B7 k4 Y - { h/ F8 R, p0 x: ?1 s
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,, p6 W: r& d! w0 g! S( ]
- viewportheight = document.getElementsByTagName('body')[0].clientHeight. c7 `# d7 k$ Z+ I! P6 l, \8 Z
- }
9 R% w$ h# W, e5 X8 M5 Y - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');* Y s0 `# U" T
- //-->
" h4 x1 k, w" V c - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯2 [0 [" I8 B5 t0 w' ?5 H; ^0 @
; A; N3 c1 d! y) a1 K) C5 e( V
/ b; o, C; A/ ~$ ~靘皞: Get viewport size (width and height) with javascript
0 U' ?8 e* h& c( c/ {+ o! `' a- {' Z
! [( w4 A! W( h# J" K, F
|
|