.Net ASP.Net – Closing page with Javascript without notification

1 Comment

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..

Image

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: ,

One Response to “ASP.Net – Closing page with Javascript without notification”

  1. Idalia Boiani Says:

    I am continually looking online for ideas that can help me. Thanks!

Leave a Reply