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.

self.opener = this;

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.

129 Replies to “Close Window in IE from javascript. (Small Hack)”

  1. In main window, there is button with caption ‘open popup’. when I press this button a popup appears which has some data, I select one option and then press submit button appearing on this popup. now interally, AJAX call is made which takes this selected data and make a search to find the records and passes these records to main window. but after this popup is not closed in mozilla firefox. but it is working fine in IE7+. Also if I press cancel button on the popup it closes.
    one more thing is that if I press submit button, data comes on the main window but popup doesnt closes, now if I click anywhere on the popup it closes.
    can anyone give me the reason and solve my problem?

  2. I am using Frames in my default page. After visiting some more pages, I want to close the previous page and come back to default page.
    The first page I am opening is not in frames. After logging in, I am opening the default page without toolbar etc. and fullscreen. I am using an in between page to make the browser settings and I want to close that intermediate page (which does not contain anything) but I get alert message window.close(). How to avoid this?

  3. Hi,
    Can anybody give me the complete html code on How to Close Window in IE from javascript.I tested the above code in Firefox version 2.0 and IE7 browser.None of the above worked..I am greatly disappointed.Can anyone help me .Thanks for ur initiative ..

  4. This is tested in IE all versions and not working in FF.
    May be it helps…

    function fullwin(){”,’_self’,”);



  5. function fullwin(){”,’_self’,”);


  6. I tried the approach suggested by above but it works for IE ,
    It wont work for firefox and netscape,

    Code :
    var self =;
    self.opener = self;

    i alsot tried
    if(navigator.appName==”Microsoft Internet Explorer”) {
    this.focus();self.opener = this;self.close(); }
    else {”,’_parent’,”); window.close(); }

    Can u plz tell me the solution ?

  7. Hi all.
    In mozilla it is not working. It is working fine in ie but fails to do in firefox.
    Please suggest any nice help

    // Code which i used”,’_parent’,”);
    // ————————————-
    thanks in adv.


    This is working in IE 7 but not working in Firefox;
    I am using StartUp.aspx to open the default page in fullscreen mode without any toolbar etc. After opening the default page, I want the StartUp page to close automatically without alert message.
    How to get fullscreen without minimize button and how to disable to CTRL key to avoid copy, refresh etc.


  9. Hi Guys,

    It seems to be a lot of workarounds with the window closing issue. I have used a combined script (using this thread) and I found it working !!!

    Here is the script:
    top.window.opener = top;”,’_parent’,”);

    It works all browsers including FF 2 and IE 7. Note that this script also reload/refresh the parent window.
    Thanks all of you!


  10. Hi,

    I’m trying to open a window with and close the opener window without having the pop up. Anyone has an idea how ?

    Best regards,


  11. Here is the complete code to close the parent window without warning; in both IE and Firefox. Paste it in an HTML and enjoy…

    function closeWindow() {
    //uncomment to open a new window and close this parent window without warning
    if(navigator.appName==”Microsoft Internet Explorer”) {
    this.focus();self.opener = this;self.close(); }
    else {”,’_parent’,”); window.close(); }

    Close Window

  12. Hi All,

    onunload () method is not fired in Opera.
    It works fine in IE, Mozilla,
    Is there any workaround for this?

    here is my script:

    The function close is not called at all.. 🙁


  13. HI This will work fine for Mozilla .
    for any info

    function ddd() {“UniversalBrowserWrite”);
    alert(“This will close Current indow”);”,’_self’);

  14. I needed to close the existing window and open the new one without menu and tool bars in IE6 and IE7.
    None of these solutions worked for me.
    So, I did the following:”,’_self’);

    function NoConfirm ()
    win = top;
    win.opener = top;
    win.close ();

    This works in IE6 and IE7

  15. I tested, It OK on IE6, IE7.
    Thanks for every comment.

    function toClose(){
    var self =”, ‘_self’, ”);
    self.opener = top;


  16. Hi guys,
    To make it work on all IE ang FF

    if(navigator.appName==”Microsoft Internet Explorer”) {
    top.window.opener = top;”,’_parent’,”);

    On fire fox actually it thinks that person who has created the window is the owner so only he can close the window or give permission to close it.

    To give permission
    under ff 2 you have to set manually under about:config
    dom.allow_scripts_to_close_windows to true
    then it?ll work

  17. Guys,

    I need the Javascript confirmation code while closing the web browser.
    when I am using onbeforeunload() in body tag for php file means its not closing(code is not working) while i am using in html file means its working but when i am calling another function to get the details about visitors means the confirmation code is not working.

    please help me to cofirmation code and getting visitors details(like name and phone number).Thanx in advance

  18. Hi,

    The above solution works in ie 8 but gives prompts me for the
    confirmation dialog to close the browser in case of ie9.

    WHat is the hack for that.

    Best Regards,

  19. hi Hidhayathulla,
    I am using the above solutions but still unable to compress that pop-up. Can u share me a snip of the code that worked for you???

  20. Excellent, Shanmugam?s trick worked in IE8.

    Fix for IE8:
    function tricky_win_close() {
    top.window.opener = top;,?_parent?,?);

    Thanks guys

  21. hi!,I like your writing very so much! proportion
    we be in contact extra approximately your post on AOL? I need a specialist in this space
    to unravel my problem. May be that is you! Taking a look forward to peer you.

  22. First of all I want to say excellent blog! I had a quick question in which I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself and clear your
    head before writing. I have had trouble clearing my
    mind in getting my ideas out there. I do take pleasure in writing but it just seems like the first 10 to 15 minutes are generally lost just trying to
    figure out how to begin. Any recommendations or tips?

  23. I conceive this website has got some rattling superb info for everyone. Dealing with network executives is like being nibbled to death by ducks. by Eric Sevareid. ddgcbaaefkcf

  24. Sometimes debugging software is important than hardware upgrade.
    If you are not sure, thoroughly read the specs for
    any tablet pc that you are considering purchasing. It’s 3Mp digital camera rear see which has
    3 instances increased potential than Apple i
    – Phone Digital camera two.

    Feel free to visit my homepage; tablets top 10 (Jefferson)

  25. If you have a history ofcardiovascular disease, diabetes,
    or glaucoma, use it only under a doctorssupervision. When this happens, you have just stopped
    – or prevented – another outbreak. Avoid foods rich in arginine such as peanuts,
    seeds, cereal grains and chocolate.

    Look at my web site: remedy for cold sore

  26. This should be done as soon as you get a new swim suit.
    If swimwear functionality takes importance more than appearance to you, think about
    purchasing these swimsuits. The gorgeous weather lately has set the mood for summer clothing, reminding us that truly warm weather is
    just around the corner.

Leave a Reply to zhangjm Cancel reply

Your email address will not be published. Required fields are marked *