Maison  >  Article  >  interface Web  >  javascript firefox 自动加载iframe 自动调整高宽示例

javascript firefox 自动加载iframe 自动调整高宽示例

高洛峰
高洛峰original
2017-01-12 11:19:441666parcourir

iframe 自动获取onload高宽 

function AutoResize(iframe) 
{ 
//firefox 
if(iframe.contentWindow) 
{ 
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight; 
iframe.width = iframe.contentWindow.document.documentElement.scrollWidth; 

} 
//IE 
else if(iframe.contentDocument) { 

iframe.height = iframe.contentDocument.width; 
iframe.width = iframe.contentDocument.height; 
} 
}

iframe 自动加载: 

var tdObj = document.getElementById('ifrtd'); 
tdObj.innerHTML = ' QQ动态加载中 ... '; 

var iframe = document.createElement("iframe"); 
iframe.src = 'http://www.zbphp.com/'; 

if (iframe.attachEvent){ 

//iframe.attachEvent("onload",AutoResize.call(iframe)); #报错 
iframe.attachEvent("onload", function(){ 
AutoResize(iframe); 
}); 
} else { 

//iframe.onload = AutoResize.call(iframe);#报错不支持 
iframe.onload = function(){ 
AutoResize(iframe); 
}; 
} 

tdObj.innerHTML = ''; 
tdObj.appendChild(iframe);

其实那个iframe.onload这里想写成iframe.onload = AutoResize.call(iframe);很遗憾,报错,不支持。 

一直不知道javascript 如何进行函数调用。比如遇到 iframe.onload = function(){} 调用函数且有参数的时候,这样的情况只能这样写,而不能像其他程序那样直接传参。 

以前看过有 apply() call(),但试过都是不支持的。为什么?

更多javascript firefox 自动加载iframe 自动调整高宽示例相关文章请关注PHP中文网!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn