I am trying to write a JavaScript function that will work on Firefox 5.0. I need the page to fully load, and then close. What I'm trying to do is:
var temp = window.open(link);
temp.window.onload = function () {
temp.window.close();
}
But so far all it does is open the new tab, but doesn't close it.
Is there any way to successfully accomplish this?
First if the link is not in the same domain, you will not be able to close the window because of the same origin policy.
Listens for the onload event with addEventListener
var temp = window.open(link);
temp.addEventListener('load', function() { temp.close(); } , false);
if you need to support old IEs than you would need to 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 up a window to hit a web page.
You can:
You could maybe create new js file for that window and have just window.close(); inside.
you can use something like
function closed(){
setTimeout("window.close()", 6000);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.