Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Thursday, April 23, 2009

Close window without the prompt message in IE7

If you tried to close a window using javascript window.close() method in IE7, and as you may noticed a message will prompt "The Webpage you are viewing is trying to close the window. Do you want to close this window". Because of the security enhancements in IE7, you can't close a window unless it is opened by a script. So the walkaround will be to let the browser thinks that this page is opened using a script then closing the window as outlined below.

Create a javascript function which will be called to close the window

function CloseMe(){
window.open('','_self','');
window.close();
}

The code in bold is used to open a window in this case it's not defined into the current window. In this way, we let the browser thinks that the current window is opened using javascript, so when the window.close() is executed it will close it without the message being displayed.

You can now close the popup window by calling the CloseMe() function at the point where you want to close your page.

Hope this helps

2 comments:

  1. Hey

    Its good and working some of the version in IE, For the global and working for all browser check another great solution :

    javascript close current window without prompt

    ReplyDelete
    Replies
    1. That's great! thanks, i will have a look at this alternative later today

      Delete

Chitika Ads