aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes window.close() alternative for cross browser. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "window.close() alternative for cross browser." Watch "window.close() alternative for cross browser." New topic
Author

window.close() alternative for cross browser.

pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 413

Hi All,

Can any one suggest me window.close() alternative which works on all the browsers like firefox, chrome and IE? I have tried following code but it doesn't work on firefox.



I have tried this as well. but it opens a about:blank page instead of closing it.




Pawan Chopra
SCJP - DuMmIeS mInD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Please read ItDoesntWorkIsUseless and reply accordingly.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 413

Sorry about that Bear. Actually we have a page which will unsubscribe users from newsletter. It has a link close window. Which should close browser window.





This close the browser window on IE. If I use below function. This close browser window on chrome. But not on firefox. So I was looking for an alternative which will work on all the browsers. Thanks and I hope now its clear.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Why do you have a window.open() call in a close function?
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 413

Bear Bibeault wrote:Why do you have a window.open() call in a close function?


I read somewhere that firefox and chrome can close a window using window.close() only if it was opened by Javascript. So this trick works for chrome. Kind of fake call.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Using hacks will never be cross-browser safe. You can only close a window that you opened yourself. Anything else is not allowed, and is very very rude. You should not be trying to close the main browser window. Please read InterfaceDesignersRule1
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Modern day browsers have tried to seal up these holes. Basically if you did not make it with window.open, there is no sure fire way of closing it.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: window.close() alternative for cross browser.