tags:

views:

695

answers:

9

how to close a browser window within given time using javascript also without the warning message in IE and Firefox

+3  A: 

Warining message is browser-dependent and you cant omit that. As far as I remember, you need to open window with script to have rights to close it.

Thinker
A: 

Use setTimeout to manage when to run your window.close() script.

EDIT : For warning message, I don't know the solution.

Canavar
I don't think he'll be able to get rid of the warning message, though.
Cerebrus
Yes I edit my post, I forgot it, don't know if there is a solution. I thing opener page can close a popup window without a warning. But we don't know if this fits to this situation.
Canavar
+7  A: 

I agree with the other guys. without looking too hard, I'd say you're out of luck closing a window in javascript without getting a warning message.

Any javascript you write will be executed by the browser. If that browser decides to trap a window.close() piece of script, then that's what it's going to do. You're constrained by the boundaries the browser places on you.

Damovisa
+2  A: 

You can only close a window (with no user warning) that was previously opened with a script.

kennebec
+1  A: 

You can't, the warning message is designed to stop code from disruptively closing windows.

A: 

For the warning message, I know StackOverflow uses the onbeforeunload event. If you override that event (not just attach a handler) with a function that returns false, it'll probably get rid of the warning. For example:

window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000); // close after 10 seconds
Chris Doggett
A: 

Just as a general principle, web browser windows belong to the user, not to you. If you are looking to create, destroy, or resize them, you are doing something wrong.

Please put your RL address in your profile. We will be sending a "reeducation team" over to visit you shortly. :-)

T.E.D.
A: 

window.close would only close the window that you have opened using javascript like window.open

Vinay Pandey
A: 

Only works in IE:

 window.setTimeout(function() { 
    window.opener='x';
    window.close();
  }, 10000);
Steve