砍敺 media 2014-12-10 19:08 蝺刻摩 4 j: t E$ Y) C& w$ @
7 s, p( ?. M; |7 H6 o% N" ?* v
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
1 h% w2 F4 J1 ?2 i6 _- <script type="text/javascript">
; |' w: ?3 o2 I' ]# C5 r - <!--
- G* J* v3 X2 Q M. Z+ _! n - + e$ k3 \2 t( p
- var viewportwidth;% P0 m6 [3 g4 m0 q) D
- var viewportheight;( V( [' @" t8 a, J
-
2 v+ A8 {8 N* b" W/ K - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
" g; P2 G' f' }9 h1 r4 y - ( ^1 ~9 }6 w3 [/ n8 G5 p
- if (typeof window.innerWidth != 'undefined')
" `* R; T d X% c) G - {
+ K4 y6 k4 X: f - viewportwidth = window.innerWidth,; Y+ f; z7 C7 C: O( I
- viewportheight = window.innerHeight
9 n$ ?8 V4 A! I% M+ b8 c - }/ S, A- g' A- g0 E7 O2 U
-
! Y0 N2 c$ b4 E - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)+ G% _7 ]! _6 ?3 u9 r; c
6 G! | a4 ^( s' y- else if (typeof document.documentElement != 'undefined'
; G+ n Q) ^9 b n/ I6 L - && typeof document.documentElement.clientWidth !=* C% ?. ~4 E6 H# K$ o2 K' G
- 'undefined' && document.documentElement.clientWidth != 0)
5 G" Q. R8 W1 C - {
& `7 ~1 O B) m+ S3 m - viewportwidth = document.documentElement.clientWidth,5 I: i; ?, S2 N' f+ `/ ?4 U
- viewportheight = document.documentElement.clientHeight
$ R8 J1 \8 ~ e5 e& x) ]1 M% Z - }
+ ]% J5 O# O8 e, R5 O+ ` -
! X9 E4 b! }3 {& s% r4 j - // older versions of IE c! |9 N# @/ ?' A: |* }/ R" v Y8 ~
- 9 `; |; P' [( a( O" y
- else
/ v" W/ R; i. D$ r% c - {
; }# U6 t% x! S4 I$ x) T - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,/ r4 p5 [$ A6 v
- viewportheight = document.getElementsByTagName('body')[0].clientHeight! o6 G" q) ]) Q5 k* ^" z
- }; C* S' p% `+ h$ r
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
% C2 i5 a+ W. O$ K( m- F# Y$ Z/ j+ x - //-->
' I7 I4 _$ B, i" o4 n; @5 s4 w - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
$ s7 j) }$ b* Q5 L, B' M
7 c1 f3 c* |' p. V8 Y( H9 I% T O2 X8 j; V, T5 H) F
靘皞: Get viewport size (width and height) with javascript( c( t- @+ {9 m! j4 p6 `
" v3 h7 K( d1 `) F! g/ n' Q
+ i$ C0 y( Q& N( E: {. b
|
|