我有这段代码从 iframe 中抛出错误:
function parentIframeResize()
{
var height = getParam('height');
// This works as our parent's parent is on our domain..
parent.parent.resizeIframe(height);
}
根本不关心这个错误。问题是它会阻止其他脚本运行。 Firefox、chrome 或任何像样的浏览器只是继续运行其余的脚本。 在运行代码之前,我需要抑制错误或确保 parent.parent 存在。
在 php 中我会写类似 if(!empty(parent.parent) {//do stuff with parent.parent }
来检查对象是否存在。
是的,嵌套的 iframe 很丑 O_o
最佳答案
尝试,
if (parent.parent && parent.parent.resizeIframe) {
// parent.parent exists and supports resizeIframe
parent.parent.resizeIframe(height);
}
这应该有效并停止错误。
关于javascript - Internet Explorer 对象不支持此属性或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3331811/