砍敺 media 2014-12-10 19:08 蝺刻摩 ) g$ Y; S5 z: k! ^" ^7 S; p4 `
1 y; e; m+ y. `$ J% z/ x
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具0 P1 [+ e% A) v2 _* p) \) O- Q* K, y
- <script type="text/javascript">
# Y: w c& U2 A$ e1 H: @ - <!--4 }5 R* m. m6 T8 Z) {6 M
: ]4 M# T1 s3 a, J% k- var viewportwidth;: [8 K* q' n! s' Z* F/ D
- var viewportheight;$ V. B- M5 z1 P9 {. A/ k& z' K# }
-
) X" k$ G6 Z) i7 d( u* [8 T - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
1 i# Q6 ~2 [; B, {: W3 f -
! O! N% p7 n$ I5 U8 b( Q# y1 c# u. j - if (typeof window.innerWidth != 'undefined')
2 H+ V1 n2 a8 G) B$ ? - {
! m) a: ]0 ?# z" G) | - viewportwidth = window.innerWidth,
$ U2 D( j. j ]8 U - viewportheight = window.innerHeight1 o$ l0 ?# ~$ p' b
- }( G: u* ?7 v3 r0 y, Z
-
6 x9 V" A/ {- G - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)/ X' \, s Z$ A, d2 F: ^! v
; d/ h0 L( Q" ?# M- else if (typeof document.documentElement != 'undefined'1 j* K. K* T5 n1 k5 W( U# |
- && typeof document.documentElement.clientWidth !=- U; S( X; n% d( P$ X1 ~* w* ]- v
- 'undefined' && document.documentElement.clientWidth != 0)+ `* [6 t8 Q' G. p
- {% S0 q9 i; t. `8 W0 a+ x
- viewportwidth = document.documentElement.clientWidth,
: H9 f9 F3 U, f+ x ?& e - viewportheight = document.documentElement.clientHeight, f& S; F. v; ?- g( g- j$ O" b
- }8 ]0 O C/ z4 h' N( A
- ( v1 y F2 Q2 m
- // older versions of IE/ J# ~( w6 T/ m% X8 N
- , V2 M6 T5 r/ e4 m
- else
% b5 W# ` f1 ?$ F) L. g# f - {
, Q. b, R& s& }* ?" p k - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
6 s9 p c9 d7 @( y9 [ - viewportheight = document.getElementsByTagName('body')[0].clientHeight
1 B9 r9 C3 S- `; J" Y - }; c$ _* H, [, X/ c
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
( r+ t' k f, M1 c8 v+ Y6 I, Z - //-->8 V) C/ i/ z7 Q; m" ]
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
: f2 B7 i W1 F2 C( @
]. l6 ~8 R; N* m' v$ U# _
2 B. b+ R" w- m! p靘皞: Get viewport size (width and height) with javascript+ S/ q% o5 m/ C9 B
* Y4 U- B# {3 D4 [
. F: B+ F6 P$ w1 Y0 {5 X |
|