3 Replies - 8952 Views - Last Post: 21 August 2008 - 10:58 AM

#1 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

how to close browser window with javascript

Posted 09 August 2008 - 05:09 AM

hi,

can any one tell me what are the ways to close browser window in javascript.

i'm trying with window.close() but it's not working in firefox..
Is This A Good Question/Topic? 0
  • +

Replies To: how to close browser window with javascript

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1153
  • View blog
  • Posts: 7,166
  • Joined: 07-September 06

Re: how to close browser window with javascript

Posted 09 August 2008 - 06:13 AM

window.close works on all browsers (I believe) but you have to rmeember that if you place it in the normal browser window (something that the user opened) it will not necessarily work. For instance in IE 6 it pops up an alert saying that the site is attempting to close the browser window and you have to allow it. It wouldn't surprise me if FF just made it so window.close is not allowed unless used in a window opened by JS.
Was This Post Helpful? 0
  • +
  • -

#3 godspeedphi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 18-August 08

Re: how to close browser window with javascript

Posted 21 August 2008 - 09:30 AM

Ya, BetaWar is right about this.

In FF it will not do anything if it is trying to close the main window. It's a security feature.

-Tim
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: how to close browser window with javascript

Posted 21 August 2008 - 10:58 AM

Though the other two are tecnically correct, it is possible in Firefox. The following function will perform this very task

function CloseWindow() 
{
    window.open('','_parent','');
    window.close()
}


Was This Post Helpful? 1

Page 1 of 1