【发布时间】:2015-10-05 08:44:58
【问题描述】:
为什么我在不同域中时无法将事件从 iframe 传递给父级
window.onload = function () {
myFrame = document.getElementById('test2');
myFrame.contentDocument.addEventListener('click', function()
{
$("test1").hide();
});
};
<div id="test1" style="width:150px;height:150px;position:relative;">
<iframe id="test2" src="http://www.w3schools.com"></iframe>
</div>
我想要这样的东西:http://jsfiddle.net/nqTnz/15/
我尝试使用不同域的相同代码但不起作用:http://jsfiddle.net/z6tco5rg/
【问题讨论】:
-
同源策略限制阻止它
标签: javascript jquery html iframe cross-domain