簡體   English   中英

JS檢測點擊DIV里面的iFrame

[英]JS detect click on iFrame inside DIV

我正在嘗試檢測對第三方 iFrame 的點擊,該第三方在另一台服務器上加載並呈現。

我在我的父 div 上添加了點擊監聽器,其中包含 iframe。 但是它的監聽器只有在我點擊 div 時才起作用,而不是在這個 div 內的 iframe 上。

有什么方法可以檢測到在我的 div 中單擊 iframe 嗎? 也許是一些 ReactJS 庫為此?

我們可以用 iframe 做的事情是,我們可以在 iframe 與 Javascript 的contentWindowcontentDocument一起使用的站點上進行操作。 試試這些,看看他們是否有幫助。

contentWindow屬性返回 HTMLIFrameElement 的 Window object。 您可以使用此 Window object 訪問 iframe 的文檔及其內部 DOM。 此屬性是只讀的,但可以像全局 Window object 一樣對其屬性進行操作。

使用 jQuery:

使用 jQuery contents() 方法

If you try to detect or capture a click event inside an iframe simply using jQuery click() method it will not work, because iframe embed a web page within another web page. 但是,您仍然可以使用 jQuery contents()load()方法在同一域上執行此操作。

試試這個資源: https://www.laravelcode.com/post/how-to-detect-click-inside-iframe-using-javascript

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM