Click to See Complete Forum and Search --> : click-to-close window ??


sydmil
12-10-2003, 12:54 PM
What is the HTML command that closes the window issusing the message:

"The web page you are viewing is trying to close the window" ?

How can I change it, so that when you reply NO, it will not close the window, but it will redirect you to a diffrent ULR.

Thanks for any tip!

cheers!

AdamGundry
12-10-2003, 01:05 PM
It's not HTML, it's Javascript, and it's something like this:

<script type="text/javascript">
document.write('<a href="window_not_closed.html" onclick="window.close();return false;">Close window</a>');
</script>

Adam

sydmil
12-10-2003, 01:27 PM
Adam,

thanks!

This command also closes the window:
<body onLoad=" window.close()">

is that also Javascript?

AdamGundry
12-10-2003, 02:18 PM
Yes, that is an event handler, which executes the Javascript code "window.close()" when the event fires, i.e. when the page loads.

Adam

sydmil
12-10-2003, 03:20 PM
Adam,

so how would you modify this event handler, so that the "NO" response will redirect you to a different location?

Thanks again!

steelersfan88
04-04-2004, 12:19 PM
I'm sure adam will be much more creative, by while I am online, it'll be easier just to post a boring one that youcan play with:<script type="text/javascript">

function newClose() {
if(confirm("The Web page you are viewing is trying to close the window.\n\nDo you want to close this window?")) {
window.opener = top;
window.close();
}
else {
// user decides not to close window
}
}

window.onload = newClose

</script>

zingmatter
04-05-2004, 10:36 AM
Browsers (or at least MSIE) will show the alert 'The window you are viewing...etc if a javascript is trying to close a window that wasn't originally opened by the parent window (this is a security thing), in which case I'm not sure if you can program a redirect into it.

Just a thought anyway.

steelersfan88
04-05-2004, 02:07 PM
well i got most of that code from adam, just implemented it to how the poster wanted it, Mozilla will find a problem with this, ehh too bad, don't use it then :)