I open a new blank tab. Now from this tab I need to open a website in a new tab. I do this as following. In its console I write:
var wild = window.open("https://css-tricks.com/", "mywin", '');
That works fine. Now I have the access of this new window with wild.document
. Now I wish to execute some code on that page after its dom will have been loaded. I use the onload
event as:
function foo(){
var mytext = wild.document.body.textContent;
alert( mytext );
}
wild.addEventListener("load", foo);
But unfortunately the alert doesn't happen. I also tried putting the event listener in anonymous self calling function as explained in this answer, but that didn't work too. I also tried ondomload event but unfortunately that didn't work too. So,
Why doesn't onload event work on a tab opend with window.open? And How to get it working properly?