访问父DOM中的iframe窗口对象 [英] Access iframe window object within parent DOM

查看:139
本文介绍了访问父DOM中的iframe窗口对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中我有来自其他域的元素。我正在使用JavaScript将第一个iframe窗口对象访问到变量中。这是代码:

I have project in which I have an elements from other domains. I'm using JavaScript to access first iframe window object into variable. Here is code :

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等没有任何问题。

I'm getting 'Permission denied' only for IE8. I have no problems with Chrome, Firefox, Safari or later versions IE11, etc..

任何人都遇到过IE8的这类问题?

Anyone has experienced this kind of issue with IE8?

推荐答案

您是否尝试过contentWindow或contentDocument方法?

Have you tried contentWindow or contentDocument method?

这样的事情应该有效:

var iframe = document.getElementById("myframe");
var iframeWindow = (iframe.contentWindow || iframe.contentDocument);

这篇关于访问父DOM中的iframe窗口对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆