LarryF
LarryF

Reputation: 5083

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;");

Upvotes: 0

Views: 3837

Answers (5)

ctrlalt3nd
ctrlalt3nd

Reputation: 1362

Bizarre, but I've found that

<script type="text/javascript">
function closeWindow()
{
    window.close();
    return false;
}
</script>

and then calling

return closeWindow();

usually gets around this.

Upvotes: 0

BC.
BC.

Reputation: 24918

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();"));

Upvotes: 3

SqlACID
SqlACID

Reputation: 4014

If the user opened the browser window, you can't close it; but if the window was opened via script, you can. Sounds like you just need an initial page that the user starts at with a "click here to begin" link, from which you open a new window for the main portion of the site; when they're all done, close the popup and they're left with their initial browser window with the "click here to begin" message.

Upvotes: 0

user65663
user65663

Reputation:

I highly doubt it's possible on your end - sounds like something a user would have to specifically disable in their IE settings.

Upvotes: 0

Richard
Richard

Reputation: 108995

I believe not. As you state to help prevent malware.

In the end the browser does not know that you are not evil. See RFC 3514 for a similar idea.

Upvotes: 0

Related Questions