2

I want to close window. my script is working fine in ie and firefox 2.x but not working in firefox 3.x and above . i am using the following script.

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

Please find some solution. thanks to all.

Gaurav
  • 28,447
  • 8
  • 50
  • 80
Abhishek
  • 957
  • 3
  • 20
  • 43
  • 2
    Please see the discussion [here](http://stackoverflow.com/questions/760422/how-can-i-close-a-window-with-javascript-on-mozilla-firefox-3). Short answer: you cannot close a window that has not been created by javascript in a patched FireFox 3. – emfurry May 27 '11 at 05:12

2 Answers2

1
function closeWindow() {
            if (navigator.appName != "Microsoft Internet Explorer") {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
            }
            alert("This will close the window");
            window.open('', '_self');
            window.close();
        }

This is working on both firefox and ie

Abhishek
  • 957
  • 3
  • 20
  • 43
  • 1
    No longer working in Firefox 8, but it does fix the warning message when using IE 8 – Alok Dec 09 '11 at 18:03
0

window.open() returns a reference to the opened window, and you can use that for close(). For example:

var win = window.open(url)
win.close()

Firefox (correctly) won't let you close a window you didn't open.

Tamzin Blake
  • 2,594
  • 20
  • 36