quqa123
quqa123

Reputation: 675

appendChild doesn't work on new window using window.open()

I've got a problem with script that works well on when I run it on current tab but when I try to use it on other widow using window.open it doesn't work. The simplified version of code looks like this:

var win = window.open("some_url");
var new_element = win.document.createElement('div');
new_element.textContent = "some text";
win.document.head.appendChild(new_element);

Im using chrome snippet tester in dev tools and it works perfectly fine when i run this stript on current window. I know it doesn't work in new widow because inspecting doesn't show any new elements. Does anybody know why it won't work? I have zero knowledge about the order of DOM creation and so on. Maybe I can't append to it until its already loaded?

Upvotes: 0

Views: 715

Answers (1)

quqa123
quqa123

Reputation: 675

After some digging I've finally got not a solution but an anwser. The reason why code did work on blank page but not on some real url's is because normally websites use Cross-site scripting blocks that are blocking such actions. So there was nothing wrong with the code. It was the site that was blocking it's execution.

Upvotes: 1

Related Questions