砍敺 media 2014-12-10 19:08 蝺刻摩 " C5 E) x% g, R/ S8 C1 l
5 ]% ~4 |# Z) v9 l! u- x餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具. S) g3 a+ L( B+ W
- <script type="text/javascript">
* {" y W$ }# n- I) o7 Y - <!--& B8 l# J# b6 ?
- # S5 L: u4 u9 J- b3 _2 [/ E
- var viewportwidth;6 ]4 u" ^( E* m/ h# f8 q9 y5 t
- var viewportheight;
7 s4 d3 k5 P! T- y7 F/ N - % ~6 \6 `5 V- @/ L, y, e7 y
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight% w# m+ N% N) C, G
-
. Z7 b' d4 c5 C) j+ Y, M - if (typeof window.innerWidth != 'undefined')9 Q- d! d0 r& l
- {0 G i& G" h! g# `2 w* j% j: p
- viewportwidth = window.innerWidth,
% K- J* n v A& ?9 p) j* z - viewportheight = window.innerHeight* u `: |3 n5 \* V* ]. {9 {
- }0 t3 E+ G0 Z6 ^+ b
- ; g; b* C- |5 {& [ C W" g. r
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
: m; r2 g6 V6 R) u8 v( r - 5 o _# B0 M$ d
- else if (typeof document.documentElement != 'undefined'
0 n9 {& \' `1 ^: w* r7 @& a - && typeof document.documentElement.clientWidth !=
& e1 c1 Y" r# t, b9 k6 _# H - 'undefined' && document.documentElement.clientWidth != 0)
5 }4 j4 d' b5 f7 s H S! X - {, ? m2 U1 I& T J
- viewportwidth = document.documentElement.clientWidth," t' h" N4 S5 |$ m2 ~3 i+ Q& C7 @
- viewportheight = document.documentElement.clientHeight4 m, j' T& x- \
- }3 K0 {! @; ~/ n/ S L
-
8 I/ e2 v$ C, d' o) G1 L; _ - // older versions of IE
5 u {% X8 U. @0 t9 E4 }2 n: } - 8 a" W6 S# c5 @9 Z5 w
- else
$ G) t3 v: l+ x5 p5 W - {
, D( N0 b: X `1 w- a5 P8 w* n3 N& @ - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
$ K5 o @- x3 c - viewportheight = document.getElementsByTagName('body')[0].clientHeight9 U. n1 [3 {& ?' _% N( v* K* z
- }
( d. U' ?0 n' m9 p' S) a( V" a - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
! q4 a1 ~( \- U/ Q! K; ~% d - //-->
3 l, O6 @7 n+ M" k* j7 C8 H- m - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯7 I, n! g* e+ d
" F4 u# M. R* g9 I
4 ?/ Q" b: B" j- U
靘皞: Get viewport size (width and height) with javascript
: G1 R+ d' M0 n0 W
: b4 x5 T, p* Z* A1 G( x: M5 k6 l5 k' a& L
|
|