砍敺 media 2014-12-10 19:08 蝺刻摩
; L3 q* z! n- A" x7 Y% `" Y8 ]
) b, h7 j# U0 k' E1 L餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具0 X/ v$ d) {6 Q4 A5 ^& ]# w
- <script type="text/javascript">
& U8 q* `# R0 j: q0 @6 B3 [, d4 _ - <!--
; H+ B, G& }- K9 Q S: j1 f - ! ~$ P. S5 g( E2 H, }
- var viewportwidth;
7 U6 n- E: o+ N0 ] - var viewportheight;
9 a: @9 h$ S$ [4 s) W. Z - 3 q5 J2 J- @5 R0 c, r- l
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight+ g" x V# G) ^, }7 d
- $ A/ I2 c4 |' a' X* Q/ p9 Z
- if (typeof window.innerWidth != 'undefined')& H$ j5 O) e3 g$ B! q3 R; Z+ R
- {
% M0 y9 Q4 e5 x# m9 q7 W0 \2 H - viewportwidth = window.innerWidth,/ |/ a) g2 S f6 x* s
- viewportheight = window.innerHeight8 ]2 O, ^! l8 r2 M
- }$ |# ?& R8 _. J" Z4 D: v- p
- 8 r% ~# X+ W- r6 S( g; b
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)0 G" U- |6 P0 W; O; I7 V
4 n0 ^& N Y( c: ^% F. S- else if (typeof document.documentElement != 'undefined'
- Y+ q, N& l$ x$ O- A6 s4 ` - && typeof document.documentElement.clientWidth !=
5 P( T7 `! a3 I" Q, q, x - 'undefined' && document.documentElement.clientWidth != 0)
/ X- H) [4 i2 x. }0 r9 i5 Y - {6 D, C- D# k5 I- Y3 b! e
- viewportwidth = document.documentElement.clientWidth,! `# A$ g, c! A" k) S7 e0 I
- viewportheight = document.documentElement.clientHeight
' t6 V7 `, g. t - } Y4 h, @7 Q3 r: A
-
9 J3 D& S& A# C - // older versions of IE: {& g* R+ a [9 _9 w
-
4 K( c" [3 }6 B$ L9 y8 n0 E" k4 f - else
" \" l9 d; Z% Q0 A% ?8 G4 y - {
9 c8 z" ^" x; Z9 f- i" \# u: i - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
2 V- k" ^1 \# r9 J A# z# B - viewportheight = document.getElementsByTagName('body')[0].clientHeight
. T2 ~9 _7 C6 v- Z* Y N - }
/ l/ e. c9 K' `* E9 k0 N8 } - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');' z' m' W: p* `8 s* H
- //-->( a5 g) u( i( f8 C' Z" k
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
6 G1 e* r2 D4 f3 }" B
1 w X) @7 E. c8 d
* c+ [1 h, h3 H" n, s' `% k! c8 Z靘皞: Get viewport size (width and height) with javascript
3 c: w/ R7 G" s V
/ v1 A: f3 H9 W+ l4 T
4 g9 {* O) ]5 n, `3 ? |
|