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.
Excellent trick this is what i were looking for, for a loong time.
Thanks
Thanks I needed this to open my web application without the toolbars. My default.htm page is now able to open the aplication window and then close itself without the warning.
Excellent!
Works good 🙂 Thanks!
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:
http://www.interwebby.com/blog/2006/02/04/3/
HTH 🙂
worked…
thks a lot bro
Sweet, just what I needed for automated printing of a folder of web docs. U Rawk Dood ;o)
-Simon
Program Files\Mozilla Firefox\greprefs\all.js must be edited to allow this to work. The pref(“dom.allow_scripts_to_close_windows”, false); needs to be set to true.
Try this, for an all in one solution:
if(navigator.appName==’Microsoft Internet Explorer’) {this.focus();self.opener = this;self.close();} else {window.open(”,’_parent’,”);window.close();}
Doesn’t work in IE7 though, still get the popup there.
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.
Try the fixed version of the script below:
if(navigator.appName=="Microsoft Internet Explorer") {
this.focus();self.opener = this;self.close(); }
else { window.open('','_parent',''); window.close(); }
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.
Regards,
Becky
great, thanks a lot
Tx soooooo much brother 😉
Its great man cooool
I am so in love with you right now…
Excellent. Been trying to sort this out all day. Top man.
This Close WINDOW in IE & FF& NS….
function tricky_win_close() {
top.window.opener = top;
top.window.open(”,’_parent’,”);
top.window.close();
}
Close
In IE7, If we opened window with target=”_blank”, the window.close() now gets this warning message. Anyone know if this will be fixed or do we have to use js to open the popup window?
thanks.
your this line
window.open(‘?,’_parent?,’?);
give me a new concept to use java script
thanks buddy
Had been looking for a common one for both IE and Firefox.
Thanks to all you folks.
very helpful. thanks!
I cannot seem to make this work in FF2.0. I get no reaction from the script. No script-errors or warnings.
Anyone else seen this?
I Cannot get this working in FireFox version 2 either.
Has anyone found a solution?
Thanks Shanmugam, and everyone alse too.
window.open('','_self');
window.close();
This will work for all (IE7 also)
This is just gr8. I was lookig for a way to do this in IE7.
Thankx a lot..
Here’s a similiar situation that I cannot find any workaround for. Best to show this one:
http://www.massimofidanza.it/firefox
Anyone know how to bring that window from the background to the foreground? I’ve spent countless hours trying to find a workaround for this bug and am very discouraged…
Pete,
You have to use different window names to prevent the pages from opening in the same window. Here is the code i’ve modified below
in ff2 doesn0t work.
bye
Hey Kumar,
Thanx for the IE7 solution! I have been looking for a work around for more than a day now but couldn’t get it done. Thanks for the nice (and o so easy looking) script!
Thanks for you IE 7 help !
I found another solution and I think this one is the complete one, if U want to close a window and open another in fullscreen mode without the “Bill’s” pop-up message in IE7 … 😉
So:
var t = (new Date()).getSeconds().toString()+''+(new Date()).getMinutes().toString()+''+(new Date()).getHours().toString();
var etc="channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=1,status=1,toolbar=0"
window.open("about:blank", t, etc );
window.open('','_self',t,etc);
document.forms[0].target=t;
document.forms[0].submit();
window.opener=null;
window.close();
window.close();
Hey Nikkkro,
Thanks for that. However I got the following error in FF 2.0 :
Error: document.forms[0] has no properties
Regards,
AJ
this functions won’t work in firefox 2.0..
how to close the window in firefox2.0
But it is still prompting for yes/no in IE7.
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.. 😉
This also works for IE7:
function closewindow() {
window.open(”,’_parent’,”);
window.close();
}
and the winner is …
window.open(”,’_self’);
window.close();
worked on everything I tried FF, Safari, etc
function closewindow() {
window.open(?,?_parent?,?);
window.close();
}
this works fine for IE 7.0 and for firefox 1.5 but not working for firefox2.0 version onwards… any suggestions appreciated.. thnx
Hi,
function closeTop()
{
var top = window.open(“”, “_top”);
//top.close();
top.focus();
top.opener = top;
top.close();
}
this works in IE6/IE7 for nested frames used in the program. Can any one suggest me to close the window without popup in FF2.
Thanks & Regards,
Satish R
Hi, im Mark and I guess im introducing myself!!
I came across this site using ‘stumble’ (Fierfox) and thought alkl the ideas floating arounnd hree seem reaally interesting! (Although I don’t seem to agree with everything lol)
Well, thats me!
How about this method? Test upper operated without problem.
(Test consisted in FF, IE6, IE7.)
———————————————————————————
window.open(‘pop.html’,”,”); // Second Popup
function tricky_win_close() {
top.window.opener = top;
top.window.open(”,’_parent’,”);
top.window.close();
}
tricky_win_close();
Great Jihoon Hwang.
Have to test in other versions also.
I am working on a webpage with multiple frames. None of the solutions suggested above works for FF2.0.0.6. Please let me know anybody who found a solution.
Thanks
Pending moderation ? Anything I am missing
These tricks don’t work on Firefox 2.0!
I’m solving with a delay to window.close like this:
setTimeout(“window.close()”,500);
On my Firefox 2.0 works great!
None of the above tricks are working in FF 2.0
please suggest
got no help from above
Thanks a lot. It worked for me in IE 7.0
var self = window.open(?”, ?_self?);
//top.close();
self.focus();
self.opener = self;
self.close();