ASP.Net – Closing page with Javascript without notification
This is a short post on closing an IE window from a button click.
This is normally a simple task. You could use code like this:
// This code does not work in Firefox 3.5 or Chrome 3.0
protected void btnClose_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>window.close();</script>");
}
And that would work…for the most part. Only in IE, you would be given this message..

Now, if you wanted to get around that message, you could need to do this:
// This code works in IE 7, Firefox 3.5, and Chrome 3.0
protected void btnClose_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>window.open('','_self',''); window.close();</script>");
}
This will no longer show the message and just close the window.
Tags: ASP.Net, javascript

Leave a Comment