![](/img/trans.png)
[英]How to detect if an element is visible within an iframe that is on a cross domain parent
[英]JS : Detect within an iframe from other domain if it is visible or not
我有一個問題,想知道放置在HTML文檔中的iframe是否可見(超過折疊)。
我的網頁: https : //oneserver.com/index.html
<html>
<head>
</head>
<body>
<iframe src="https://otherserver.com/index.html></iframe>
</body>
</html>
另一個網頁(不是在父iframe可見時應該做的事情:
<html>
<head></head
<body>
<script>
if(document.isVisible()){document.style.background="red"}
</script>
</body>
</html>
我嘗試使用Page Visibility API和一個jquery技巧,但是到目前為止,我沒有找到任何解決方案。 您能在這件事上幫助我嗎?
非常感謝 !
為了確定它是否可見,它必須能夠檢測父窗口的大小以及該窗口滾動了多遠。
標准的跨域安全性使得無法從框架內部實現這一點。
最好的辦法是讓父頁面中的代碼檢測框架何時進入或離開視圖,然后使用postMessage API將該事件告知框架中的頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.