Home > Technical & Creative Skills > Programming, Servers & Scripts

Alert box on closing the page and on CTA button (3)


02-28-2017 05:53 PM #1 davidep (Member)
Alert box on closing the page and on CTA button

Hi everybody!

Ok we all know about scripts that make an alert box appear when users want to close the page. I'm using this one now.

<script type="text/javascript">
window.onbeforeunload = function() {
return "Don't go away! You can win an iphone!"
}
</script>
What I would like to do is to make an alert box with a certain message appear when they close the page and another one when they click on the button that will bring them to the offer page. What happens now is that the same script appears in both the cases.

Can someone help?

Thank you


03-01-2017 02:37 PM #2 vortex (Senior Moderator)

Here's an example:

https://www.dropbox.com/s/y7y6m2tsm7...-pops.zip?dl=0

Basically: You set up an exit pop, but add the condition "PreventExitPop !=false", where the exit pop is only triggered if this condition is met.

Then when you're wanting for another message to pop up when the visitor is clicking the CTA to go to the offer, set "PreventExitPop=false" to disable the exit pop, and at the same time specify another function to make the other message pop up.


<a target="_top" href="your-tracker-click-url" onclick="exit_a1();PreventExitPop=false"></a>


function exit_a1(){alert("This is the message you want the visitor to see when they click on the CTA, before sending them to the offer.");}


<script>
var PreventExitPop = true;
function ExitPop() {if(PreventExitPop != false) {
return "This is the message you want visitors to see when they exit but not through the CTA."}}
window.onbeforeunload = ExitPop;
</script>
Hope that helps!



Amy


03-01-2017 08:16 PM #3 davidep (Member)

Fantastic! Thank you so much Amy


Home > Technical & Creative Skills > Programming, Servers & Scripts