is there a way in javascript to open a link in a new page and append on this page a div?
Lets suppose that I have page1.html which contains a div with a link and two radio buttons "yes" and "no" I want to open the link in another page and put on this page the div with the radio button over the content of the second page.
For the moment I use this example code but it does not work
// open the URL in a new window
var win = window.open("https://www.google.com/", "_blank");
win.addEventListener("load", function() {
var n = "<div><h1>Hello from the new window!</h1></div>";
win.document.body.innerHTML = n;
});
the URL can be anything and it is not on the same domain of the first page
2
Answers
The short answer is no for pages that are not in the same domain as the parent page. That would be an invitation for malware to masquerade as a search agent and then intercept any interactions with pages opened from the parent page.
If you want to open a link in a new window that is not on the same domain as the current page and also modify its content, you can
This approach works because the HTML content is not actually being modified on the target page, but rather it is being passed as a parameter to the page. Doing this without interacting with the other page involves additional server-side code or browser extensions. But keep in mind this can be a security risk and can also violate the terms of service of the website.