通过内容脚本将事件处理程序添加到动态创建的IFRAME

发布于 2025-02-05 21:19:24 字数 473 浏览 3 评论 0原文

我有一个Firefox扩展程序,通过内容脚本将事件侦听器添加到网站上的所有元素中:

document.addEventListener('click', function eventHandler(e) {
   // do something
})

在大多数情况下,这可以正常工作,但是当单击动态创建的IFRAMES中的元素时,EventHandler函数并未触发,例如就在 https://www.deepl.com/contact-us?cta=whydeepl = https:/ /a>

“ all_frames”:清单中的true标志已设置,并且配置为匹配所有URL,因此不应该是问题。

有没有办法使它起作用?

I have a Firefox extension that adds event listeners to all elements on a website through a content script:

document.addEventListener('click', function eventHandler(e) {
   // do something
})

This works fine in most cases, but the eventHandler function is not triggered when clicking on elements in dynamically created iframes, for example, the form on the right on https://www.deepl.com/contact-us?cta=whydeepl

The "all_frames": true flag in the manifest is set, and it is configured to match all URLs, so that shouldn't be the issue.

Is there a way to get this to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初懵 2025-02-12 21:19:24

已解决:只需要在清单中设置“ match_about_blank”:true。

Solved: Just needed to set "match_about_blank": true in the manifest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文