|
登录后查才能浏览下载更多咨询,有问题联系QQ:3283999
您需要 登录 才可以下载或查看,没有账号?入住遨海湾
×
先申请精华~
! T7 |! } ?. O& C8 l4 B+ m) ?. l' N
看完一定要顶啊~- U( _( O$ r$ M1 @; f, N
/ ~& M7 f6 a" Y* a! C A; K
先说明,这个办法只限于iframe中的子页面也是本地页面(不能引用外网页面)
5 c& ]- Z9 S/ e0 S3 D g/ n+ U/ q1 h: e; j
======方法=====
7 D2 I! T1 L8 A% q7 a8 t第一步 js部分
" ?3 B4 n \. A+ j; i& R( Y4 ~
% H/ O/ {" t7 b( F$ \- rfunction getSize() {
" B" E* z8 b( R2 j+ b. l var xScroll, yScroll;
9 w1 R% w3 V/ o' E4 T8 y if (window.innerHeight && window.scrollMaxY) {
% Y, h1 j& P2 i& p& N1 i/ _ xScroll = document.body.scrollWidth;
8 P2 U5 O* E% V; t6 e/ ^$ x. W yScroll = window.innerHeight + window.scrollMaxY;
% ^7 O1 ]" Y! b1 p% r; S } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
9 X% }* S& ?0 K% m8 P6 E xScroll = document.body.scrollWidth;2 {3 v2 ]: [+ B! p! z
yScroll = document.body.scrollHeight;8 d. ^, e( @; {9 K1 T
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
/ I. l' E' V* z+ x- X xScroll = document.body.offsetWidth;
1 D+ ]- u3 Y# \* {* R: u yScroll = document.body.offsetHeight;
/ Q+ d5 a, z5 f- n }
; ^7 ]5 O5 M' _4 j$ `( ?" M9 o8 h+ W0 s; R% ?& ]+ F% V5 @
var windowWidth, windowHeight;" d- v9 `9 x* q3 P5 ?" G5 f2 p$ R1 \
if (self.innerHeight) { // all except Explorer
/ C' V( P2 q/ @+ i$ v/ t: L windowWidth = self.innerWidth;
/ I2 _5 Z. t) A2 r t windowHeight = self.innerHeight;! ~0 G* w$ w5 {
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
) H- {! @% h1 J; H windowWidth = document.documentElement.clientWidth;
9 @. z# k- P9 q3 _! K5 \3 A windowHeight = document.documentElement.clientHeight;
( G( G' h O! R! Y } else if (document.body) { // other Explorers. e/ t6 @ B Y' T$ r. [
windowWidth = document.body.clientWidth;0 _* \) m* W7 F1 J' R: D* z4 i! x6 \
windowHeight = document.body.clientHeight;! s8 m! f& @/ b' ]+ v6 T
} * K* H# Z7 T5 ~8 U, v$ E
K1 i6 j' l% o2 I/ B // for small pages with total height less then height of the viewport
: ^8 p* W4 A6 M( ^8 @" A8 ^ if(yScroll < windowHeight){5 n, v7 _( K1 N$ W
pageHeight = windowHeight;3 d! n8 h9 @$ O2 |) Z, g
y = pageHeight;
L: u$ \$ x7 w. t } else { " H: \0 j4 n7 e% ?
pageHeight = yScroll;$ Z! x! W: q5 w5 {' K
y = pageHeight;
1 ?$ ]" F/ \# |- g O/ R( f& F/ V/ [5 p }
! H9 r$ t* i2 H0 t+ ?/ p6 p% U9 B# D L5 }1 d# ]: o- `4 c, j3 u
if(xScroll < windowWidth){
7 }! F, ?2 n- }( Z9 D4 l) n6 I pageWidth = windowWidth;
$ g5 Z9 c- F% C6 [ } else {
8 \6 z$ x* _. _ d0 `" N) i pageWidth = xScroll;+ h# r( z e# ]# a! ~, v5 l
}
6 z3 f- h% z* @3 C5 E3 a( t; j* ^% V! R
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 6 b9 r; Q3 Z, b2 j% L8 }: t* A% ]
return arrayPageSize;
4 q) x1 _7 a# G- R}4 V; ^$ k4 h+ ?% ^8 i. Y0 \: E
这段代码用来获取目标页的参数,包括页面高、宽,屏幕高、宽
4 p2 q* t l# ]" O$ C" A2 |4 I4 u) N
function autoHeight(pid) {
% j+ f$ j$ x5 h, k5 [( e var x = new getSize();2 _$ p0 m9 f# f6 k6 C8 N9 G: a
parent.document.getElementById(pid).height=x[1];
1 P1 @2 X% j* T7 m9 @' E( g}
0 @0 g. h/ h, V- t0 A这段代码用来实现父页面中iframe的高度自适应
) d2 X8 |6 w& p; L0 J% s
$ P8 N- L8 z) {* F6 T\\\\\\\\\\$ r: H/ A/ X# A( z
3 f' z' ^ `5 ]" b5 j第二步 页面部分
4 U( d; |* C. j# a. n1 b' R$ Z& L: i* O( O1 k
<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>
0 |7 K/ `5 Z* C4 _2 D7 b这是父页面的iframe,没什么特别的,和普通的iframe一样,不过要设置好id值,以便子页面的参数调用。$ H8 M( A; U5 x9 x/ A. i/ o
8 e4 C! s& [4 {8 \/ Z' ]
<body ></body>
) D7 ?6 L7 x& P2 u* o8 O在body中利用onload事件,将自身的高度传给父页面的iframe。, O2 M1 @( T$ T& a# z8 R
2 S4 R1 `% }( U4 ]
\\\\\\\\\\
0 c5 P& y G0 L' G: s) K
* W' T" b5 W" L7 G打完收工~本方法在IE6,FF2,XPsp2下顺利通过,FF无报错~ |
|