PDA

View Full Version : Is there a script for confirming site exist with an alert box?



Gabber
11-14-2004, 03:55 PM
Is there a script for confirng site exist with an alert?
I want something that says yes or cancel (or similar) in a alert message before leaving the site. but usually using "confirm" and pressing cancel button does the same as the yes button (leaves the site).

<HTML>
<HEAD>
<SCRIPT>
function closeIt()
{
event.returnValue = "Any string value here forces a dialog box to \
appear before closing the window.";
}
</SCRIPT>
</HEAD>
<BODY onbeforeunload="closeIt()">
<a href="">Click here to navigate to</a>
</BODY>
</HTML>


this actually works out, but I don't want the extra text. is there a way to get this effect without the extra text? just my text, and confirm box working?

ddadmin
11-16-2004, 04:47 AM
Trust me, it's really not a good idea to use prompt boxes in this way, as most users will really find it annoying. Unfortunately you can't remove that default message that pops up, as it's part of IE's security measures to always give the ultimate choice to the user. It's similar to when you try and close the main window using JavaScript- an alert message pops up.

Gabber
11-16-2004, 08:09 PM
yes... I know that...
the ideia is nto annoying... I was surprised people liking it (it gives info about time spent). yet, I don't ask to change the alert in itself... but the alert type. instead of just ok button. have ok and cancel too.
the confirm value instead of "event.returnValue " does the trick but does not work well for quitting windows...because cancel makes it quit too... how do I solve this?

ddadmin
11-16-2004, 08:11 PM
Hmm I'm confused- "quiting windows?" Can you explain what exactly you're trying to do with a confirm box? Obviously you can't give people a choice between quiting Windows or not using JavaScript.

cr3ative
11-17-2004, 06:45 AM
We could try modifying this script if this is what you mean...

http://javascript.internet.com/messages/yes-or-no-confirm.html

cr3ative

Gabber
11-17-2004, 06:21 PM
yes! :) indeed that is the type of alert box... just want that for exiting the page... the box could also have configurable text... and when ok is pressed, one leaves... when cancel is pressed, one stays (also an alert message could appear as an option).

:)
thanx for the attention

cr3ative
11-17-2004, 06:48 PM
You can try this... I've just been fiddling around with it.

But I warn you, if I were a web user on your page, this'd annoy me a lot.



<head>
<SCRIPT LANGUAGE="JavaScript">
function getit() {
askit = confirm("Leaving so soon? Why not stay a little longer!");
if (askit == true)
window.location=window.location.href
else
if (askit == false)
alert("Visit again soon!");
}
</script>
</head>
<BODY onunLoad="getit()">
Your webpage here.
</body>
</html>


cr3ative

Gabber
11-18-2004, 05:20 PM
thanks for the effort, but that is not it...hum. how can I explain this...
try this:

<HTML>
<HEAD>
<SCRIPT>
function closeIt()
{
event.returnValue = "Any string value here forces a dialog box to \
appear before closing the window.";
}
</SCRIPT>
</HEAD>
<BODY onbeforeunload="closeIt()">
<a href="">Click here to navigate to</a>
</BODY>
</HTML>

try this script...
now I want the same without the additional text that appears no matter what you write instead of "Any string value here forces a dialog box to \
appear before closing the window."
get my point?
greetz

cr3ative
11-18-2004, 05:52 PM
Erm... no, I don't get your point... :)

cr3ative

Gabber
11-20-2004, 01:43 AM
the script you modified does not work. when I press cancel, leaves the page, altough it shows an alert.
I want an alert when I made alt+f4 or righttop X or try to leave the page somehow... and when I say ok in that alert I leave. when I say cancel, I stay.

Gabber
11-30-2004, 02:40 PM
hello, have your figured a solution out?