砍敺 media 2014-12-10 19:08 蝺刻摩
; @. u: E4 d! T6 _
5 o) J: h4 Z4 G1 S: @& \3 p餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具1 c" h) m5 G% O8 ~6 b6 ?* W
- <script type="text/javascript">
9 V3 O, s: o) f - <!--
n# J) E# _/ Q! B& J0 U
8 j! `5 ~7 c$ P; R- var viewportwidth;0 q' U q: n) \$ t. H: Y& }, ?: E
- var viewportheight;! ^5 q2 `2 \* {/ [& l
- 7 U$ O) {) n0 `! ]1 R3 i
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
, ^4 h% M1 p( {2 s' ]/ B8 O! v -
' Z8 D8 Q2 m+ G7 [4 f! L2 c - if (typeof window.innerWidth != 'undefined')
! Z* c4 C, g! H8 E. J - {
( t X1 A2 t; O$ M5 u& a1 z - viewportwidth = window.innerWidth,
6 `) Z# f' D: N - viewportheight = window.innerHeight5 z9 V- ]' g9 u* ~( o$ N
- }# o, k" P |: \ \# _% R
-
+ X# ]% q y1 r8 P - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) x$ o7 r! u- g5 Y$ ~, w! [& }
- * t* }8 l3 Z# ~8 V: G
- else if (typeof document.documentElement != 'undefined'
) m- v: t2 p6 l3 H) Z7 U. I - && typeof document.documentElement.clientWidth !=
0 O2 h! ]2 t7 K2 Z% J* a; b - 'undefined' && document.documentElement.clientWidth != 0)
. i- Z b, B; ]. n - {
# s/ I1 Y3 e, [4 j - viewportwidth = document.documentElement.clientWidth,
; S/ C/ B$ |; f - viewportheight = document.documentElement.clientHeight. t6 s2 [5 S8 ^
- }
7 n6 H& @$ B6 l, [7 W$ a - # Z7 d7 t5 ~0 K7 C6 q2 k- N* J
- // older versions of IE E- d7 D7 j5 N; o8 n2 W
-
! Y& k- e- ^' j! O, o9 N- J - else9 K7 t" P. `. m9 ?7 ?
- {
/ _+ c/ O7 ]4 ?& x - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,! r% k: z+ b6 I: Q/ H! l
- viewportheight = document.getElementsByTagName('body')[0].clientHeight* y9 s! C8 a$ i, A0 w% z4 ?; q' S
- } E/ z8 r! z. V3 y3 ^. \6 b
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
8 @2 E1 l% Z0 I/ O$ `7 C. h h - //-->
+ \, \0 h" `+ V$ @1 a6 l3 t0 w - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯6 ?4 ^) J8 \! c
6 t. c" {, [* q% P* u
* E9 x+ b! u" ^' F1 l, d9 N. g靘皞: Get viewport size (width and height) with javascript
1 l) n! X* X1 Y1 ?: D
8 b8 F* S) j, s2 O% z7 l/ v' B% _( |% m( Z8 w* d
|
|