If you've ever tried to close a browser window from ASP.NET by using the following code:

 

<input type="button" class="inputfields"
 onclick="javascript:window.close();" value="Close" /></td>

You will probably receive the following message:

 

After digging around for 20 minutes or so, I finally found the answer on Anatoly Lubarsky's blog:

 

<input type="button" class="inputfields"
onclick="javascript:window.opener='x';window.close();" value="Close" /></td>
 

10 Responses to JavaScript: How to Close Browser Window (window.close()) Without Warning

  1. SathishKumar says:

    Hi,

    This doesnt work in IE7 and Firefox 2.0.Any help thanks

  2. Manoj says:

    Try
    window.opener = self
    window.close()

  3. Tom says:

    Still get message asking if you want to close the page.

  4. Mani says:

    function OpenMyWin()
    {

    window.opener='X';
    window.open(",'_parent',");
    window.close();
    }

  5. Shahriar Sayed says:

    Thanks a lot Mani.

    It works nicely in IE7.

  6. RaiulBaztepo says:

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I'v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

  7. Cesar Alpendre says:

    To close a window without warning message, try this:

    Close Window

  8. vikash says:

    write these lines on button click.

    response.write("(window.close;)")

  9. sunil says:

    window.onfocus = function() {window.open(", '_self', "); window.close(); }

  10. Sujitha says:

    function closeMe()
    {
    var win=window.open("","_self");
    win.close();
    }

    then
    please set your firefox browser:

    1.input "about:config " to your firefox address bar and enter;

    2.make sure your "dom.allow_scripts_to_close_windows" is true

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>