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);
}
轉載于:https://www.cnblogs.com/liulf/archive/2011/05/25/2057154.html
總結
以上是生活随笔為你收集整理的iframe 自适应高度 跨域的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《优化算法》人工鱼群算法学习 超详细解
- 下一篇: Nginx 笔记与总结(14)expir