我不知道這是否與工作不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? –