在谷歌翻译中,我制作了谷歌翻译的第二个实例
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:
我正在尝试这个(如果我只是在 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
,但似乎没有任何作用。
我将非常感谢任何帮助。