Avatar of tddeffner
tddeffner asked on

Onbeforeload firing twice

I am having an issue with an on before unload firing the twice.  Iit works fine bring up my vbscript error, but if I hit cancel, it asks again, with different menu saying, Are you sure you want to navigate away from this page?"

What could be causing this?
VB ScriptProgrammingASP

Avatar of undefined
Last Comment
b0lsc0tt

8/22/2022 - Mon
b0lsc0tt

tddeffner,

Probably your code for the onbeforeunload.  Please post it.  Remember the event will automatically pop a message so if you have added a confirm then that is your problem.

Let me know if you have any questions or need more information.

b0lsc0tt
ASKER
tddeffner

Here is the code.  
<script language="VBScript">
	sub back_button()
	error=msgbox("Are you sure you wish to leave this test?", vbokcancel, "Warning")
		if error = 1 then
			back_form.submit()
		else
			window.event.returnvalue=false
		end if
	end sub
</script>
 
<body onbeforeUnload="back_button()">

Open in new window

ASKER CERTIFIED SOLUTION
b0lsc0tt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
tddeffner

That doesn't seem to work i keep getting a Expected Statement Error.  
Your help has saved me hundreds of hours of internet surfing.
fblack61
b0lsc0tt

I will look into that but does the client side script have to use Vbscript?  It will only work in IE if you do that and I just don't ever use it for browser script.  This won't affect the vbscript you use for ASP.  If this is all the clientside script you will do then let's do it in javascript.

bol
b0lsc0tt

I can still come up with javascript if needed but I found the way to do it with clientside vbscript.

Let me know how it works or if you have a question.

bol
<script type="text/vbscript">
Sub back_button()
	window.event.returnValue = "Are you sure you wish to leave this test?"
End sub
Set window.onbeforeunload = GetRef("back_button")
</script>

Open in new window

ASKER
tddeffner

Well i like to be consistent, and this is an intranet site its going on, where we are suppose to be using IE.  I got it figured out though, so thanks guys.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
b0lsc0tt

Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol