包含外部wesbite的iframe不会触发onscroll事件处理程序 [英] iframe containing external wesbite does not fire the onscroll event handler
问题描述
据我所知,为了正常触发iframe中的onscroll事件处理程序,iframe必须包含一个与包含iframe的页面具有相同域名的站点。但无论如何,这可以做一个包含外部网站的iframe吗?
onscroll事件处理程序:
< script type =text / javascript>
window.onload = function(){
var frm = document.getElementById(test)。contentWindow;
frm.onscroll = function(){
alert(iframe scrolled);
}
}
< / script>
以上js代码适用于此:
$ b $ < / iframe>< b>
但这不是:
<$ p $ >< iframe id =testsrc =http://www.< anExternalSite> .com>< / iframe>
如果我无法做到这一点,我的整个应用程序将毫无用处。有没有解决这个问题的方法?任何破解?
任意外部网站?否。
合作外部网站?让滚动事件侦听器由站点本身(绑定到它的body元素)绑定,并使用 postMessage 。
I understand that in order to fire the onscroll event handler in an iframe normally, the iframe must contain a site with the same domain name as the page that contains the iframe. But is there anyway at all that this can be done for an iframe that contains an external site?
The onscroll event handler:
<script type="text/javascript">
window.onload = function() {
var frm = document.getElementById("test").contentWindow;
frm.onscroll = function(){
alert("iframe scrolled");
}
}
</script>
The above js code works just fine for this:
<iframe id="test" src="http://www.<myDomain>.com"></iframe>
but not for this:
<iframe id="test" src="http://www.<anExternalSite>.com"></iframe>
If I can't do this my entire application will be useless. is there any workaround for doing this? any hack?
Arbitrary external sites? No.
Co-operative external sites? Have the scroll event listener be bound by the site itself (to its body element) and communicate the event data using postMessage.
这篇关于包含外部wesbite的iframe不会触发onscroll事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!