I'm trying to embed Google Translate into Google Translate with iframe. I used the code:
var a = document.createElement('iframe');
a.src = "https://translate.google.com/";
a.id = "iframenaturalID";
a.width = "400";
a.height = "1100";
document.querySelector('body').appendChild(a)
But it creates another instance of Google Translate inside the iframe. So I get one iframe inside the main window, and the second iframe inside the first iframe.
I tried doing this (and multiple variations with window.parent
[but I guess that works only when calling the parent window from iframe]):
var bodydocumentmain = document.getElementsByTagName("body")[0];
bodydocumentmain.id = "bodyMainID";
var innerMainBodyDoc3 = document.getElementById("bodyMainID");
var innerMainBodyDoc = innerMainBodyDoc3.contentDocument || innerMainBodyDoc3.contentWindow.document;
var a = innerMainBodyDoc.createElement('iframe');
a.src = "https://translate.google.com/";
a.id = "iframenaturalID";
a.width = "400";
a.height = "1100";
innerMainBodyDoc.querySelector('body').appendChild(a)
But that doesn't work. Of course I could simply do:
var iframe1 = document.getElementById('iframenaturalID');
var innerDoc = iframe1.contentDocument || iframe1.contentWindow.document;
innerDoc.getElementById('iframenaturalID').remove();
But that seems a bit crooked. Is it possible to make an iframe only inside the main window, without affecting the first iframe?