我有一个项目,其中包含来自其他领域的元素。我正在使用 JavaScript 将第一个 iframe 窗口对象访问到变量中。这是代码:
var iframes = window.frames;
//grab first iframe
var ifrWindow = iframes[0].window; // Here is where I get **Permision denied**
ifrWindow.postMessage("hello",IframeDomain);
我只收到 IE8 的“权限被拒绝”。我在 Chrome、Firefox、Safari 或更高版本的 IE11 等上没有问题。
有人在使用 IE8 时遇到过此类问题吗?
最佳答案
您是否尝试过 contentWindow 或 contentDocument 方法?
像这样的东西应该可以工作:
var iframe = document.getElementById("myframe");
var iframeWindow = (iframe.contentWindow || iframe.contentDocument);
关于javascript - 在父 DOM 中访问 iframe 窗口对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27351786/