Close Window in IE from javascript. (Small Hack)

When trying to close an window from javascript in IE, which is opened manually,
a security warning “The web page you are viewing is trying to close the window. Do you want to close this window? Yes|No ” is popping up. Is there any possibility to close a window silently? Yes.

A simple hack i found on the web will help to get rid of this situation.

this.focus();
self.opener = this;
self.close();

but in Firefox you can do this. Firefox will not allow you to close using the above code. Maybe anybody found/having any code post it here.

I was asked to make the window.close thing possible in FireFox at work the other day, searching everywhere and seeing everyone say it wasn’t possible didn’t sound good so I came up with my own way – read about it here:

To all who would like a Javascript solution that will close the browser window using FireFox, you should us JL’s solution above, however, it won’t work unless you fix the invalid characters in the script. They are only minor errors but still big enough to cause the script not to run.

All that is different is the apostrophes around the “Microsoft Internet Explorer” text (‘ ‘) have been changed to quotation marks (” “). There is also another stray character in the line:

window.open('?,'_parent?,'?);

If you can see, it appears just after the apostrophe, after the first open bracket.

Anyway, I hope that fixes any problems for people using that solution. Oh, and just a note on browser compatibility. I have tested this script in Internet Explorer 6, Mozilla FireFox 1.5 and Opera 8.51 – they worked perfectly in all browsers.

1.FOR [AJ] & [venu] -> u’r wright…it might not work in firefox…but my solution was exclusiv for IE7…cose I used it for a task in an web-based application running under IE6 or IE7 platform…so I wasn’t confrunted with such a problem 😉 …but u’r free to carry on …and solve this problem

2.FOR [AJ] about the …it depends on how many forms do u have in u’r page…and to what form do u refer to….in the script…(forms[0] or forms[1] etc.)

3.FOR [zaheerabbas] for me, it worked every time since I used that…so review u’r code and see if u wrote it with no mistakes.. 😉