我找了一个javascript脚本,它将改变iframe的高度,根据其中加载的页面,我找到了一个代码,但它只适用于IE和FireFox ..我该怎么改变?
<SCRIPT type="text/javascript" LANGUAGE="javascript">
function reSize()
{
try{
var oBody = ifrm.document.body;
var oFrame = document.getElementById("ifrm");
oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
}
//An error is raised if the IFrame domain != its container's domain
catch(e)
{
window.status = 'Error: ' + e.number + '; ' + e.description;
}
}
</SCRIPT>
iframe代码:
<iframe width=940px onload=reSize() src="html/guides.html" id="ifrm" name="iframe_main" frameborder="0"></iframe>
感谢您的帮助!
答案 0 :(得分:2)
对于初学者:
document.all
已经过时了一段时间。
您应该使用getElementById。
此外,如果iframe不在您的域中(例如,您在www.mydomain.com并且iframe从www.someotherdomain.com加载内容),您将无法获取iframe的document.body大多数现代浏览器的常规安全设置...... See here for details
答案 1 :(得分:0)
尝试var oBody = ifrm.contentDocument.body || ifrm.contentWindow.document.body;
答案 2 :(得分:0)
为您的iframe提供ID。我给了“myIframe”,然后在你的函数中使用这一行而不是你的。它随处可见:
document.getElementById("myIframe").setAttribute("height",600);