gpt4 book ai didi

javascript - createElement 只在主文档中,而不是在文档内的 iFrame 中

转载 作者:行者123 更新时间:2023-11-30 06:44:42 28 4
gpt4 key购买 nike

如果我用...创建一个元素

var elm = document.createElement("p");  
document.body.insertBefore( elm, document.body.firstChild );

我在每个 body 元素中都有这个 p 元素 - 太棒了!
而且在主文档中的每个 iframe 主体中。

如何在主文档中定义创建?像什么?

document.body.firstChild.ownerDocument

(脚本应该通过 safari 扩展从 injected.js 完成工作)

最佳答案

i got this p-element inside every body element - cooool!

您应该只在文档所具有的单一主体中获取它。

but also in every iframe body inside the main document.

那些是单独的文档,除非您在嵌入文档中包含该代码,否则该代码不应触及它们。

如果您在这些文档中包含该代码,那么您可以测试看看您是否(不)在一个框架中:

if (top === window) {

关于javascript - createElement 只在主文档中,而不是在文档内的 iFrame 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7969140/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com