View Full Version : Help Building on a Exit Splash Alternative

05-25-2012, 04:49 AM
Here's the base code:

<script type="text/javascript">
var exit=true;
function confirmExit()
return "Message Goes Here";

But it doesn't do exactly what I need it to

What I need (and think is possible, I'm just missing how to do it) is to use this script to make sure they're leaving the site (there's more to the script [that is placed on links] to declare what will not trigger it) But instead of returning to the viewer on attempted exit this 'leave or stay on the page' dialog, I think this script would be better if it would return with a regular confirm box - which will display a message and offer to redirect them to the page I want them at using a OK to redirect them, and cancel to just leave the page however they intended.

I tried just playing with the original script but found that Google Chrome and IE would do different things when trying to follow it - which is why I want this to launch a confirm box which I can link a straightforward redirect to.

Any help?

Old Pedant
05-25-2012, 05:33 AM
And WHEN is your confirmExit function called?? Via window.onunload??

If so, you can't change the location at unload time. It's a browser safety feature to prevent sites from holding users captive.

05-25-2012, 01:24 PM
<body onbeforeunload="return confirmExit()">

Could I just modify this to call a confirm box rather than the confirmExit one used in the script?

Old Pedant
05-25-2012, 07:55 PM
No. onbeforeunload has VERY strict rules. It can be used in one way and one way only.

06-01-2012, 04:50 AM
Is there a way to disable the script activating when a page refreshes or the back button is pressed?

Old Pedant
06-01-2012, 05:02 AM
Disable what script? The onbeforeunload? Yes, easy.

function closeIt()
if ( youDoNotWantTheDialogToAppear ) return false;

return "Your message asking them to stay on the page';
window.onbeforeunload = closeIt;

Of course, now you have to figure out HOW or WHY they are leaving the page and set that youDoNotWantTheDialogToAppear value appropriately.

So in your case, you'd have to figure out they were doing BACK or refresh and return false. Not sure how you want to do that.

06-09-2012, 02:22 PM
Ah. Well I happened upon a spell of luck and came across a website that had the actual script installed - and not called externally so I was able to copy it. I think if I could tweak it to not set off the function controlling exit actions on the refresh button - it would be perfect!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum