在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();
這樣就可以正常調用父頁面的方法了。
總結一下分享,讓后面的小伙伴少走點彎路。