views:

2140

answers:

2

Is there a way to bypass the following IE popup box:

The webapge you are viewing is trying to close the window. Do you want to close this window? Yes|No

This is occurring when I add window.close() to the onclick event of an asp.net button control

+7  A: 

Your JavaScript code can only close a window without confirmation that was previously opened by window.open(). This is an intentional security precaution because a script running on a webpage does not own the window, and by closing it discards the browsing history in that window.

The workaround is to either have a "welcome page" or otherwise some sort of page that pops up the window you want to close with window.open in the first place, or to tell your users to modify their browser security settings to allow your application to close their windows.

Tmdean
The web page was generated by the user clicking a link in a e-mail sent by the application.
Michael Kniskern
You can try making the link like <a href="http://your.web.app.com" onClick="window.open('http://your.web.app.com/'); return false" />Click me</a>. But I doubt that many mail clients will run JavaScript. Unfortunately, I think you might be out of luck.
Tmdean
You are right, I am out of luck. I had to implement a different solution.
Michael Kniskern
+1  A: 

There is a hack for this.

for IE call:

window.open('close.html', '_self');

then in close.html all you need is:

<script>window.close();</script>

Since this essentially opens a popup, in the same named window, when the "new' window opens, it has an "opener" and thus is allowed to close.

scunliffe
Would I add the window.open call to the onClick event of the anchor tag. See Tmdean's comment in answer 1?
Michael Kniskern
I tried your solution but it will not work in our environment because javascript has been disabled in our e-mail client. Thank for the input.
Michael Kniskern