Close window without the prompt message

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. below is the implementation.

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

<script language=javascript>

function CloseWindow()
{
window.open(”,’_self’,”);
window.close();
}
</script>

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.

Now you can try it by adding the below HTML code,

<a href=”” onclick=”CloseWindow();”>Testing Close Window</a>

Hope this post will help you.

Below is the example to close the parent window closing while chid get opend,

var win =window.open (“URL”,”TITLE”,”width=1200,height=740,location=no”);
win.moveTo(0,0);
win.resizeTo(1200, 870);
window.open(”,’_self’,”);
window.close();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: