Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

window.close() alternative for cross browser.

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65114
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read ItDoesntWorkIsUseless and reply accordingly.
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65114
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have a window.open() call in a close function?
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65114
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic