砍敺 media 2014-12-10 19:08 蝺刻摩
: c6 I- H9 |- ^; p
4 y2 |8 Q- C6 ]1 B餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具& m, b# Q2 T) ?3 T. d6 z
- <script type="text/javascript">
/ m7 M, X/ f' q0 _" B! k) b d! w+ u - <!--) H1 S0 w( M- r
+ `5 c8 E. [9 w% T- var viewportwidth;+ g4 v" J) c9 J9 C
- var viewportheight;' {3 u: m8 w+ n8 T
-
6 L# o. r s) }6 L# L- A! { - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight ]0 N) x2 h# X% ]
- ^' ?! k: e6 }+ P4 `! l8 `" u- L
- if (typeof window.innerWidth != 'undefined'). ]& _& o9 S* F5 P" p. H
- {( P; l& E. {# n* f2 Z/ l
- viewportwidth = window.innerWidth,$ m" \6 s6 D8 _0 G) Q" Y) V% \+ \
- viewportheight = window.innerHeight
/ P, j) h) _5 H+ q* Q - }
& R6 F2 q5 Z' J/ Q - * f$ A2 Q) V3 F
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)* R+ S/ w- ?: o7 X, y& p
- ' D5 f) y" S4 @9 B8 C
- else if (typeof document.documentElement != 'undefined'# Q$ i6 R: p6 H5 V- a' a0 F
- && typeof document.documentElement.clientWidth !=
; S6 c& J) u7 q0 _* b/ G8 i - 'undefined' && document.documentElement.clientWidth != 0); I. O+ K' H+ s
- {
/ A* s7 _: U2 u! y) P: k - viewportwidth = document.documentElement.clientWidth,
2 }2 m _ t7 i. ?, g, W y- ` - viewportheight = document.documentElement.clientHeight
7 p4 L" K4 z# c- w* R, P( t: a - }" A: H( W2 K' C9 g" H
-
# p1 k! P S( y- V( P7 j - // older versions of IE
' p$ p% p- |- M; ] -
8 ?3 S* a1 W% c) ` - else( I* P( t5 k) O# i m h9 {
- {
3 s" e; b: K: A - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
0 K# p6 m' ]" |: }. ` - viewportheight = document.getElementsByTagName('body')[0].clientHeight
! P& x2 ] @- d. _! j - }* f# a8 n. G3 t5 W
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');1 P% ~! A3 t0 H9 c
- //-->" r" }- b5 a q% Y# K9 h
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯, z5 h1 J- u# r7 {, A. h0 A
+ l+ e( m% D: D# o* [
! S& H$ z0 S+ b! X靘皞: Get viewport size (width and height) with javascript
' W9 {; W& Z; i- `, _9 V
- U3 s' m6 m' R$ l: z; `
" S, Y. ^5 m- {& V& T+ b |
|