C# – Closing an IE ‘popup’ window with script


Is it at all possible to disable the "The webpage you are viewing is trying to close the window. Do you want to close it?"?

I understand that this is the product of years of virus, and malicious script activity, but in legit app code, (ASP.NET), is there any way to like "register" your app as an APP, or flags you can pass to an IE Popup so that it will not display this when it closes?

The code I'm using is done from within the C# code behind:

ClientScript.RegisterClientScriptBlock(GetType(), "save", Utils.MakeScriptBlock("window.close();")); 

The Utils.MakeScriptBlock is just a function that does what you might expect. It 'injects' a <script…> tag with the code in it…

It's probably not possible to get around this, or else, all the script kiddies would just use that trick, but I thought I'd ask, as I can't be the ONLY one using simple IE "popups" as (pseudo)modal dialog boxes.

This code happens in my ButtonSave_Click() routine, after everything has passed validation, etc…

** EDIT **
Just for reference, here is the code that OPENS the popup, when the ADD button is clicked:

This is in Page_Init()…

ButtonAdd.Attributes.Add("onclick", "window.open('Add.aspx', 'ADD_WINDOW', 'scrollbars=no,width=550,height=550,location=no,menubar=no,resizable=yes,directories=no,status=no,toolbar=no'); return false;");

Best Solution

You can close the window without the popup if the window was opened by your script. Does that help?

Edit: You're already opening the window with script. Change your client script to call self.close().

ClientScript.RegisterClientScriptBlock(GetType(), "save", Utils.MakeScriptBlock("self.close();"));
Related Question