Forum Moderators: open

Message Too Old, No Replies

Redisplaying page in OnUnload

Redisplaying page in OnUnload

         

DIsrael

12:54 am on Dec 24, 2003 (gmt 0)

10+ Year Member




I've got a window that I want to pop up when the user closes it (only closes when they click OK).

I read a message on here a long time ago where somebody succeeded in doing that, but no details. Can anybody give me a kick in the right direction? Thanks.

CloudLong

5:44 pm on Dec 25, 2003 (gmt 0)

10+ Year Member



I'm not sure this work exactly you want it to be or not, but this one will close the window and then the confirmation box will appear, if the user click cancel button, it will reopen it again.

<html>
<head>
<!--
Code By "CodeFreak" Cloud - codefreak.proboards19.com - 2003
You may leave this part of code intact to show your gratitude or remove it
-->
<script language=javascript>
function confirmit()
{
var closeit= confirm("Do you really want to close this page?");
if (closeit == true)
{window.close();}

else
{window.open("test01.html");}
}
</script>
</head>

<body onunload="confirmit();">

Body content goes here.

</body>
</html>

note: test01.html is the code page name, you can change it to whatever your page name is.

Hmm is this code fulfill your needs?

CloudLong

5:50 pm on Dec 25, 2003 (gmt 0)

10+ Year Member



Sorry for double post, but this really important. Plz replace the function above with this one instead.

<script language=javascript>
function confirmit()
{
var closeit= confirm("Do you really want to close this page?");
if (closeit == true)
{}

else
{window.open("test01.html");}
}
</script>

I remove the window.close() function because there are the times the user will change the url but not intend to close the browser.

CloudLong

6:09 pm on Dec 25, 2003 (gmt 0)

10+ Year Member



Okay, I almost make a recode for triple posting. But I do brought you good news :)

<html>
<head>
<!--
Code By "CodeFreak" Cloud - codefreak.proboards19.com - 2003
You may leave this part of code intact to show your gratitude or remove it
-->
<script language=javascript>

function confirmit()
{
event.returnValue = "You can add some comment Here";
}

</script>
</head>

<body onbeforeunload="confirmit();">

hahhahahhahaa

</body>
</html>

This code will work perfectly as you wish.
how ever the "Are You sure you want to navigate away from bla bla" cannot be removed or altered..
Instead of onunload, I use onbeforeunload, so the page will not be close down :)

EDIT: OMG, there is an edit button! sorry about that.. 2 above post can be delete.

DIsrael

10:25 pm on Dec 25, 2003 (gmt 0)

10+ Year Member




The onbeforeunload doesn't work if you are not using IE... I may play with the onunload stuff. Thanks for helping!