砍敺 media 2014-12-10 19:08 蝺刻摩 ' r" C8 s" D3 h3 |
- z+ P5 J: o6 l& _8 t6 H5 i
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
' [9 |6 K3 A* i h9 g6 c0 s/ X- <script type="text/javascript">
. V" |# h9 I s* R; B! V - <!--+ k$ i* E8 p" |) H# k
- + a/ P" g' ~# ?! l
- var viewportwidth;
* E9 O& @' \; C: P- K0 F3 {( ] - var viewportheight;, [: `6 ?: U' D) d. a6 L
-
: X4 U0 g5 d. ?) s4 s' y - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight$ N. q% X3 d4 D5 u& s
-
: x' C. Z. x/ M - if (typeof window.innerWidth != 'undefined')
% J8 G% d4 a/ I9 | - {- I) R0 I4 ^& L: X* u% J* B
- viewportwidth = window.innerWidth,
) V: K! ]6 p% j; _" L - viewportheight = window.innerHeight
/ p5 d. j, ~' d ^) z# u - }. F& U, k& `/ ?& }% H5 a9 {: j
-
3 x7 U% L4 o( T; I - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document), k8 k) n. Q1 p( K& A" s$ Z
- : _9 z/ N! B! n
- else if (typeof document.documentElement != 'undefined'" q; d/ m3 }6 s8 f$ M4 ^; [) ~
- && typeof document.documentElement.clientWidth !=
. j& I! E( k1 G! j$ j+ i0 p0 ^ - 'undefined' && document.documentElement.clientWidth != 0)
8 L) i0 [$ d$ n5 p) Y1 P! b$ G+ q4 ^4 E - {
% t& L" r8 ~" B& H - viewportwidth = document.documentElement.clientWidth,
1 W# h# ^8 g' m# Z2 y - viewportheight = document.documentElement.clientHeight5 y {, k6 K* g; ]( g6 x: m7 \" F. `
- }
7 r$ T% z( |! n( A5 H* r -
" ~1 a! I: w5 S! s/ h' d1 E - // older versions of IE- i7 G" ? E1 h) G
- # B. i3 D0 |$ m) d( y
- else
3 {- G5 G' |- M/ H& O/ Y - {( g! Y1 f! k/ x0 p& R" q: `
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
' X3 m5 a4 H/ @9 E* P$ { - viewportheight = document.getElementsByTagName('body')[0].clientHeight8 ~8 F4 ?! J- R/ E; s2 d
- }
9 X/ x& ^7 l+ m - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');) J& a9 h9 A' A* ^" z7 T
- //-->% B# U! ~9 i5 t. C* @
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
9 Y2 m! r# A% F
/ g# {3 J9 n; U) ?: W
5 c! [& Q- m) j) I" @: Y/ W2 a( o
靘皞: Get viewport size (width and height) with javascript: G0 @1 n' S) q0 H7 R" \& S
6 g$ O% N2 ~' d. F
% A+ [ j* V' h" j |
|