将 div 从父网站复制到 iframe 中的文本区域

2024-01-09

在谷歌翻译中,我制作了谷歌翻译的第二个实例

var makediv = document.createElement("secondinstance");
makediv.innerHTML = '<iframe id="iframenaturalID" width="1500" height="300" src="https://translate.google.com"></iframe>';
makediv.setAttribute("id", "iframeID");
var getRef = document.getElementById("gt-c");
var parentDiv = getRef.parentNode;
parentDiv.insertBefore(makediv, getRef);

And I'm trying to copy text from auto-correction of the first instance to the textarea of the second instance: image

我正在尝试这个(如果我只是在 Chrome 检查器中复制 html{使用 [0] 或 [1] 选择具有相同 ID 的元素},此代码就可以工作,但是只能使用带有 iframe 嵌入的翻译器的两个实例):

setInterval(function() {
    var childAnchors1 = window.parent.document.querySelectorAll("#spelling-correction > a");
    var TheiFrameInstance = document.getElementById("iframeID");
    TheiFrameInstance.contentWindow.document.querySelectorAll("#source").value = childAnchors1.textContent;
}, 100);

但是控制台说它无法读取 eval 处未定义的属性“文档”,并说问题出在这一行:

  TheiFrameInstance.contentWindow.document.querySelectorAll("#source").value = childAnchors1.textContent;

我尝试过嵌入另一个网站,但也不起作用。我还尝试通过“iframenaturalID”调用iframe,并尝试编写TheiFrameInstance.contentWindow.document.querySelectorAll没有contentWindow,但似乎没有任何作用。 我将非常感谢任何帮助。


最近尝试访问 iframe 时遇到类似问题。不幸的是,如果它是跨域的,这是不可能的。阅读更多:从 iFrame 中获取元素 https://stackoverflow.com/questions/1088544/get-element-from-within-an-iframe

希望能帮助到你。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 div 从父网站复制到 iframe 中的文本区域 的相关文章

随机推荐