我不知道这是否与工作不CORS或任何网站,但我需要这个曾与多个iframe具有不同ID的 - 当你点击 https://jsfiddle.net/ab0a/1fyoajqc/6/
<!-- Multiple iframes with different IDs -->
<iframe id="iframe" src="https://livestream.com/accounts/5690925/events/6124324/player?width=960&height=540&enableInfoAndActivity=true&defaultDrawer=feed&autoPlay=true&mute=false" width="960" height="540" frameborder="0" scrolling="no" allowfullscreen></iframe>
<iframe id="iframetwo" src="iframe/here/too" width="960" height="540" frameborder="0" scrolling="no" allowfullscreen></iframe>
<iframe id="iframethree" src="iframe/here/as/well" width="960" height="540" frameborder="0" scrolling="no" allowfullscreen></iframe>
<div id="message"></div>
<script>
var monitor = setInterval(function() {
var elem = document.activeElement;
if (elem.id == 'iframe') {
message.innerHTML = 'One';
//use clearInterval(monitor); if you want to stop checking
//clearInterval(monitor);
}
if (elem.id == 'iframetwo') {
message.innerHTML = 'Two';
//clearInterval(monitor);
}
}, 100);
/* If you only want to check for a specific iframe once, but still want to check for others, set up another monitor for that specific iframe */
var monitorTwo = setInterval(function() {
var elemTwo = document.activeElement;
if (elemTwo.id == 'iframethree') {
message.innerHTML = 'Three';
message.style = 'background-color: red;';
clearInterval(monitorTwo);
}
})
</script>
点击事件只会触发iframe的边框不是里面 – RRR
你将不得不监听器绑定到页面的iframe内。 (我相信有这一个易受骗的人) – epascarello
我不能到里面页面上添加一个监听器,因为它链接到另一个网站。无论如何,我可以检测到有人点击iframe而没有用范围之类的东西来掩盖iframe? –