Forum Moderators: open

Message Too Old, No Replies

onBeforeUpdate() Question

         

u2ill

8:18 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



I'm using the onBeforeUpdate event in the <body> tag to open a dialog box that tells clients that if they close the window during the credit card payment process, it will be assumed that they plan to pay by check.

I would like to run a server-side script that sends me an email if they choose "OK" (they choose to close the window). Can anyone tell me where to put the code that detects they clicked "OK" and will open a new window to the server-side script BEFORE the original client window closes?

Purple Martin

11:00 pm on Mar 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you say "dialog box", I assume you mean you're using alert(). You could use confirm() instead, like this:

var clickedOK = confirm("Stick your message here.")

It has two buttons (OK and Cancel) and returns a boolean value: OK --> true, Cancel --> false.

u2ill

12:08 am on Mar 10, 2004 (gmt 0)

10+ Year Member



Okay, I can use the confirm() function in the onBeforeUnload event. But if the user decides they want to stay on the page, how do I stop the onUnload event?

Purple Martin

12:19 am on Mar 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Found this relevant article:
[webreference.com...]

dcrombie

5:14 pm on Mar 10, 2004 (gmt 0)



AFAIK this is only available in Internet Explorer so I wouldn't use it for anything important...

The answer to your question is probably to have the onBeforeUnload event handler return false.

eg.

function someFunction () { 
if (somecondition) return false;
return true; // default
}

<BODY ... onBeforeUnload="return someFunction();">

u2ill

9:54 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



I ended up using the onBeforeUnload event. Then I change the href.location to a page which runs a PHP script that sends an email notifying of the impending window closure. I ran into a problem with the onBeforeUnload/beforeUnload events running to fast, and the PHP script not getting called in time, so I added an alert() just after the href.location letting the clients know that because the credit card process did not complete, it will be assumed they are sending in their payment by check (this is for a college application submission).

I understand that onBeforeUnload is only IE, but that's what 90% of the people out there are using...it's the best I can come up with right now...