我在寻找一个可以改变 iframe 高度的 javascript 脚本,根据其中加载的页面,我找到了一段代码,但它只适用于 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>
感谢您的帮助!
最佳答案
对于初学者:
document.all
已经过时很长一段时间了。
你应该使用 getElementById .
此外,如果 iframe 不在您的域中(例如,您在 www.mydomain.com 中并且 iframe 从 www.someotherdomain.com 加载内容),您将无法获得 iframe 的 document.body大多数现代浏览器的正常安全设置... See here for details
关于javascript - 脚本不适用于 chrome,只能用于 ie 和 firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13142712/