Naftuli Kay
Naftuli Kay

Reputation: 91630

Unified way of closing a browser window in JavaScript?

Is there a way to simply close a browser window, guaranteed? Last time I heard, calling window.close() or self.close() only works when the current window is launched from another window. Is there a way to get the majority of browsers to close the current window when this isn't so?

Upvotes: 3

Views: 2420

Answers (3)

Rohit Suthar
Rohit Suthar

Reputation: 3628

Try this one (Working in Chrome & IE) -

function closeWindow() { 
window.open('', '_self', '');
window.close();
} 

Upvotes: 1

Alaa Jabre
Alaa Jabre

Reputation: 1883

in firefox you can't close the window that the user opened you can just close the window you opened firefox not allow that because of security reasons take a look at this: http://support.mozilla.com/en-US/questions/749393

however that's work with IE

hope it helped

Upvotes: 1

Jason Benson
Jason Benson

Reputation: 3399

There is no way to close a parent window via script without prompting in any major browser.

So nope, no guarantees. On a child window, window.close and self.close both work great.

Upvotes: 8

Related Questions