0

My aim is to have a exit pop up which triggers the window.onbeforeunload if somebody tries to close the current tab or browser. But after they complete a sign up form to opt in to my e-mail list and redirect to my "Thank you page URL", I do not want the exit pop up to show. I am using a page builder, so the code is not written by myself.

This is the following script I am using:

 window.onbeforeunload = function(e) {
 return 'Are you sure you want to leave this page?  You will lose any unsaved data.';
    };
</script>

As for my form, because after the user enters their name and clicks submit, they redirect to a URL and the exit pop is triggering once the redirect begins. I only want the pop to show if they try to leave opting in then disable this after they take that action.

I notice an a class tag with the href="submit-form" My form is also contained in the form target tag if that helps.

How do I implement a script which disables the exit pop up after redirecting to a new page in a HTML sign up form?

Thank you for any insight.

1 Answers1

0

You could achieve that by using if-else statements and setting the event to null if a form is being submitted. Here is an example

`

window.onbeforeunload = function(e) {
e.preventDefault()
if($('form').submit(){
    return null;
}
else{
return 'Are you sure you want to leave this page?  You will lose any unsaved data.';
}
}

`

PS: I have not tested it but it should work

Neville Lemein
  • 177
  • 1
  • 9