|
登录后查才能浏览下载更多咨询,有问题联系QQ:3283999
您需要 登录 才可以下载或查看,没有账号?入住遨海湾
×
先申请精华~
) {/ ]8 I3 ~1 T1 a7 ~5 e; @* o/ U$ W B1 ]2 y. s' r6 `
看完一定要顶啊~
# X9 G2 ?0 V( d9 J/ r- _ z5 K5 `$ E# F* s* Q }1 X; W n
先说明,这个办法只限于iframe中的子页面也是本地页面(不能引用外网页面)
+ ?" c+ E' c& M4 k
$ T0 W2 w' p) G8 o1 }: c======方法=====
; K; M2 y! k- Q: t7 y$ Z1 Y: E第一步 js部分 }! h |1 o4 U+ k& o0 r/ a
8 ^; W; m" I+ ]# _
function getSize() {
" t- D/ d% y# V" D1 t& y$ V var xScroll, yScroll;
5 o6 S7 t7 L( c8 Z if (window.innerHeight && window.scrollMaxY) { l% E& e, u1 t7 i
xScroll = document.body.scrollWidth;
. ~( T0 m& [. A. e% ^8 [: N/ w! z yScroll = window.innerHeight + window.scrollMaxY;
+ p9 c" y2 z1 L4 |6 w w- ]) F Q } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac& y) l7 L5 K0 |6 |$ y3 s
xScroll = document.body.scrollWidth;2 S0 D* j6 s. @* G% Y8 \1 }) u2 R
yScroll = document.body.scrollHeight;
& v3 e: L) X) {2 l# m } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari0 e4 U9 h; z" }, i% ]
xScroll = document.body.offsetWidth;7 `8 n) ?/ F8 r& y/ F
yScroll = document.body.offsetHeight;7 ~, q: [7 |& D& p7 Q, \0 y
}
$ Q: l3 J$ n, K4 D. o/ }7 Y+ m5 D0 i8 J6 M& w* S# C1 Q3 J* V- G
var windowWidth, windowHeight;& i0 A4 f( s3 E$ r; W
if (self.innerHeight) { // all except Explorer4 Y# V3 e5 Z& @
windowWidth = self.innerWidth;+ [5 L h+ D* K
windowHeight = self.innerHeight;6 v9 w* _) y7 E5 I: e
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode& c- @! ~% i- `
windowWidth = document.documentElement.clientWidth;
" _) o0 R1 r: N) Q* X windowHeight = document.documentElement.clientHeight;
7 I* S: A/ d- C' n0 E) B } else if (document.body) { // other Explorers
/ N3 ]% N0 D+ ^1 a( g# x% @# t windowWidth = document.body.clientWidth;
0 W: }" j# b! ^# v5 _ windowHeight = document.body.clientHeight;
7 R1 E) l3 G. h! Y. Q% @- U2 O } ' D, T1 }7 a/ }8 v6 \. I
9 a) w# M/ r# H% k% x9 Y
// for small pages with total height less then height of the viewport, e0 A& p( p1 R. g1 [
if(yScroll < windowHeight){( d* w# S2 a- H# y/ Z @7 {
pageHeight = windowHeight;! p7 z" F# m7 t* R0 G
y = pageHeight; M1 B) z7 o* f" H
} else { ( Z! R. ~4 Q S8 G) v0 y6 m
pageHeight = yScroll;
0 l) r% d* Z/ W8 a9 [* x y = pageHeight;* u1 \: w& j- l, \# e
}" ~0 i7 \8 z2 ^" \5 B
} z1 R" @9 s, U
if(xScroll < windowWidth){
6 q- Z4 F4 v Z3 d5 ^ O pageWidth = windowWidth; @) v8 T2 k* s0 ^% @$ d$ m7 z
} else {
! E: C( [% _2 ` pageWidth = xScroll;
# @, T! A7 u0 }8 O0 ]* v }! P3 W% l. z' k6 [$ s& R8 q$ O. E
6 x8 F4 c8 i8 v! a, c arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
9 Q8 {7 M: p0 p1 @: c* K return arrayPageSize;
7 ]+ Z$ q- w* ? p- f% u}
8 O$ g( U$ C! A* @1 Y3 S这段代码用来获取目标页的参数,包括页面高、宽,屏幕高、宽. O! e0 D% W, d8 f; O7 l8 v
0 V$ z. C, I* W
function autoHeight(pid) {
. v) q }& I( m var x = new getSize();
; V* x: l4 `5 O# v parent.document.getElementById(pid).height=x[1];
1 h4 l6 S* M# C# U6 q: R8 o) P}
6 U# `# \' a/ M1 N2 e' F" U% o这段代码用来实现父页面中iframe的高度自适应
6 r( q+ X0 t2 P: w/ D+ u
0 K1 x2 ^6 T- O: f7 f\\\\\\\\\\" g4 Y+ Y, _" D
2 Q) _$ E, ?# z I% H5 `0 ^第二步 页面部分7 S `- A/ `9 a
/ @/ e o( E' n" G1 b
<div class="onright" style="width:480px;"><iframe id="infrm" name="infrm" marginwidth="0" marginheight="0" width="100%" src="park.htm" frameborder="0" scrolling="auto"></iframe>
% y2 Y0 @ f+ U8 X- Z这是父页面的iframe,没什么特别的,和普通的iframe一样,不过要设置好id值,以便子页面的参数调用。
( R8 \( C( g4 k: h
% T q! ]+ O9 e* J8 i! u0 t& K& I$ U! u<body ></body>
& u* o( b* |& q. v8 u v在body中利用onload事件,将自身的高度传给父页面的iframe。/ ?; S+ o3 J0 x* f! P; B( t
R y/ I! {! o4 X
\\\\\\\\\\
, C9 n8 i, V Z8 w, c( i% J" z- x- ~+ \. ~8 c( R1 v! M& I4 t
打完收工~本方法在IE6,FF2,XPsp2下顺利通过,FF无报错~ |
|