无法获取未定义或 null 引用的属性“contentWindow”

在iframe 中有时候 这样使用contentWindow 会报 无法获取未定义或 null 引用的属性“contentWindow” 这种情况 我是在IE中遇到 其他浏览器一切正常。

parent.frames[top.$(".J_iframe:visible").attr("id")].contentWindow.Tanchu();
parent.frames[top.$(".J_iframe:visible").attr("id")].contentWindow.Tanchu();

要让IE兼容要这样写:

parent.document.getElementById(top.$(".J_iframe:visible").attr("id")).contentWindow.Tanchu();
parent.document.getElementById(top.$(".J_iframe:visible").attr("id")).contentWindow.Tanchu();

这样就可以正常调用父页面的方法了。

总结一下分享,让后面的小伙伴少走点弯路。

在iframe 中有时候 这样使用contentWindow 会报 无法获取未定义或 null 引用的属性“contentWindow” 这种情况 我是在IE中遇到 其他浏览器一切正常。 parent.frames[top.$(".J_iframe:visible").attr("id")].contentWindow.Tanchu(); 要让IE兼容要这样写: parent.document.getElementById(top.$(".J_iframe:visible").attr("id")).contentWindow.Tanchu(); 这样就可以正常调用父页面的方法了。 总结一下分享,让后面的小伙伴少走点弯路。
经验分享 程序员 微信小程序 职场和发展