PDA

View Full Version : Closing windows without an alert when running under Vista



mgglasby
01-01-2008, 08:34 AM
Hi,

I have been looking for a quick solution to this and haven't managed to find one yet and I hope someone here can help.

The code I am using to open a new window is ordinary HTML Ie.

<a href="austin.html" target="_blank">Robert Austin</a>

In the new window I use a button to allow the reader to colse it Ie.

<input type="button" value="Close this window" onClick="window.close();">

When running under Windows XP this didn't cause a problem but now with VISTA I get an alert message asking if I really want to close the window.

I have read some info that suggests this is a new 'security' feature in Vista and that there is no way round it. If anyone has found a better way of doing this could you please let me know.

Thanks

Marc.

tech_support
01-01-2008, 08:59 AM
<input type="button" value="Close this window" onClick="window.opener=self;window.close();">

jscheuer1
01-01-2008, 06:17 PM
That's fooling the browser, or trying to. It will fail in FF and others. The only way to be relatively sure that you can close a window with javascript is to have opened it with javascript:


<a href="austin.html" target="_blank"
onclick="window.open(this.href,this.target);return false;">Robert Austin</a>

Then on austin.htm:


<script type="text/javascript">
document.write('<input type="button" value="Close this window" onclick="window.opener=self;window.close();">');
</script>

Using document.write makes it so that only browsers that can use the button will see the button. It could be refined a little more by testing to see if the page was actually open by javascript, but that's a little complicated to do cross browser, and even if it wasn't opened by javascript, many browsers will still comply. At the least, you will get a confirmation and option to close. But, if the page was gotten to from a link like in the first code block, virtually all browsers will accept the close.

mgglasby
01-02-2008, 12:31 PM
Thanks for the solution :) that has solved quite a big problem :)) now all I have to do is a bunch of editing :(

Regards


Marc