Detecting the onload event of a window opened with window.open
If the pop-up's document is from a different domain, this is simply not possible.
Update April 2015: I was wrong about this: if you own both domains, you can use window.postMessage
and the message
event in pretty much all browsers that are relevant today.
If not, there's still no way you'll be able to make this work cross-browser without some help from the document being loaded into the pop-up. You need to be able to detect a change in the pop-up that occurs once it has loaded, which could be a variable that JavaScript in the pop-up page sets when it handles its own load
event, or if you have some control of it you could add a call to a function in the opener.
Onload event is not firing after passing Html string through window.open in Angular 8
When using document.write()
, you have to call document.close()
afterwards to finalize the document, otherwise the load
event will not be fired.
const win = window.open('', '_blank', 'left=50,top=50,width=1334,height=700');
win.document.write(htmlData);
win.document.close();
windows popup onload event not working Javascript
Since it's not the same domain , you will not be able to access the window set properties.
Try this here in console
(function(ow) {
ow.addEventListener("load", function() { alert("loaded"); }, false);
})(window.open('https://stackoverflow.com/', 'example', 'width=300,height=300'));
This will work
But if you put a different domain , it will not work. You'd have to use PostMessage
or something else.
how to detect window.open
You can replace it
NOTE: window.open does not work at stackoverflow due to sandboxing
Also a window.open not triggered by a user action will likely be suppressed by the browser
const saveOpen = window.open;
window.open = function(url,windowName,parms) {
console.log("triggered",url);
saveOpen(url, windowName || "",parms || "")
};
const url = "https://stackoverflow.com", windowName="myWin"
setTimeout(function(){
window.open(url,windowName);
}, 1000);
window.onload not firing when window is already open
As I stated in my comment, if the window is already open, what do you expect it's load function to do? It's already loaded. Close the window and it loads the window again.
You can use the window.close
function to close the window and then open it again.
wconsole.close()
Related Topics
JavaScript Callback When Iframe Is Finished Loading
Why am I Seeing an "Origin Is Not Allowed by Access-Control-Allow-Origin" Error Here
How to Determine the Number of Days in a Month with JavaScript
Add Property to an Array of Objects
When a 'Blur' Event Occurs, How to Find Out Which Element Focus Went *To*
JavaScript Es6 Computational/Time Complexity of Collections
Why Does JavaScript Replace Only First Instance When Using Replace
Google Chrome Console.Log() Inconsistency with Objects and Arrays
Detecting the Onload Event of a Window Opened with Window.Open
How to Access a JavaScript Variable Using a String That Contains the Name of the Variable
How to View Events Fired on an Element in Chrome Devtools
How to Initialize an Array's Length in JavaScript
How to Use JavaScript Source Maps (.Map Files)
How to Get First and Last Day of the Current Week in JavaScript
Pure JavaScript: a Function Like Jquery's Isnumeric()
Why Aren't Some Technically Serializable Input Properties Serializable
Angular2 Router 2.0.0 Not Reloading Components When Same Url Loaded with Different Parameters