始终无法监听到,是什么原因?
parent.html
<body>
<iframe id="iframe" src="son.html" frameborder="0"></iframe>
<script src="./jquery.js"></script>
<script>
$(function(){
$($('#iframe')[0].contentWindow).on('dosomething', function(){
alert('接收到到iframe的事件');
});
});
</script>
</body>
son.html
<body>
<h1>son</h1>
<button id="button">trigger</button>
<script src="./jquery.js"></script>
<script>
$(function(){
$('#button').on('click', function(){
$(window).trigger('dosomething');
});
});
</script>
</body>
谢谢!
Dont
刚才搜索时发现的,也不错,兼容性可以
MessengerJS
https://github.com/biqing/Mes...
跨文档通信解决方案
son.html
事件是在父页面的jquery里定义的,要触发需要交由父页面的jquery来负责触发。
jquery源码太久没看了,找半天,没找到对应的内容来说明。