Attach An Onload Handler On A Window Opened By Javascript
I want to be able to know when a user navigates away from the page I have loaded in a window opened by Javascript. For example if I have: newWindow = window.open('http://www.exampl
Solution 1:
You can do it like this:
newWindow = window.open('http://www.example.com', 'testWindow');
newWindow.onload = function() {
alert("loaded");
};
You can give it a try here. There are restrictions however, the window must be on the same domain, to be in compliance with the same-origin policy (the onload
event just won't be hooked up otherwise). In the example that weird domain is the same as the test frame, this is very important...try changing the domain or protocol and you'll see it doesn't work, and you'll get an error in your console.
Post a Comment for "Attach An Onload Handler On A Window Opened By Javascript"