How to close main browser window with out getting warning message

When you try to close the main browser window using the close [ window.close(); ] method. You get the confirmation prompt

The Web page you are viewing is trying to close the window.
 Do you want to close the window?

This warnning message appears only if you are trying to close the main browser window and not the popups. To stop this use the following snippet

function closeMe(){
window.opener = "";
window.close();
}

It works because the browser checks for the value of window.opener to see if it is a child window or main window. if the value is null then it assumes the window to be main window. Now we are cheating the browser by assigning the window.opener to some random value!

6 Responses

  1. Mads Kjaer says:

    Although this may be a clever workaround, you should NEVER close, minimize or change the size of a users window(s) without him or her confirming the action first. This is an example of extremely poor usability.

  2. zalifer says:

    That would be the coolest thing ever… For someone to exploit with XSS… te he he.

  3. albert gregory says:

    Im trying to close a browser window down without success there must be a simple solution.

  4. Mithun Bagchi says:

    The above script is not working in Mozilla.Could anyone please give me the mozilla compatible code to close the main browser (not popups)?

    Thanks

  5. amayer says:

    Yes, everybody says that this is a good solution. Where/how do you apply it? In the redistry? Somewhere in IE? Create a new “.js” file with notepad? HOW?

    function closeMe(){
    window.opener = “”;
    window.close();
    }

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.