Closing the window after full page load
I am trying to write a JavaScript function that will work in Firefox 5.0. I need the page to fully load and then close. I am trying to do this:
var temp = window.open(link);
temp.window.onload = function () {
temp.window.close();
}
But for now, all it does is open a new tab but not close it.
Is there a way to accomplish this successfully?
+3
source to share
4 answers
First, if the link is not in the same domain, you will not be able to close the window due to the same origin policy.
Listens for onload event using addEventListener
var temp = window.open(link);
temp.addEventListener('load', function() { temp.close(); } , false);
if you need to support older IE than you would need attachEvent
var temp = window.open(link);
temp[temp.addEventListener ? 'addEventListener' : 'attachEvent']( (temp.attachEvent ? 'on' : '') + 'load', function() { temp.close(); }, false );
There is no need to open a window to get to the web page.
You can:
- Make Ajax request - must be the same domain
- Set hidden iframe
- Set image source
+3
source to share