1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > iframe 自适应高度 跨域

iframe 自适应高度 跨域

时间:2023-12-04 03:55:45

相关推荐

iframe 自适应高度 跨域

window.navigator.Allframes=null;

window.navigator.Allframes = { 'iframe1': window };

//根据页面name属性查找到子页面所在Ifame对象

window.navigator.getFrameByName=function(oName){

return this.Allframes[oName]

};

//将一个Iframe对象注册到window.navigator.Allframes数组中

window.navigator.registerFrame=function(oName,oElement){

this.Allframes[oName]=oElement

};

window.navigator.createFrame = function (childPage) {

var fun = function () {

this.objChildPage = childPage;

this.getFrameByName = function (oName) {

return window.navigator.getFrameByName(oName)

};

this.resizeHeight = function () {

try {

var height = this.objChildPage.document.body.scrollHeight;

if (this.objChildPage.document.getElementById('iframe1').name && height) {

var curIframe = window.navigator.getFrameByName("iframe1");

curIframe.height = height+120;

return document.body.scrollHeight+120;

}

} catch (ex) {

//异常处理

alert(ex);

}

}

};

return new fun();

};

//在body.onload中调用

function AutoResizeHeight(){

try {

var control = window.navigator.createFrame(this);

control.resizeHeight();

}catch(ex){

alert(ex);

}

}

//当iframe onload 的时候

function myAsync() {

AutoResizeHeight(this);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。