Please help me about Javascript redirect

by 4 replies
5
I have searched everywhere and I cannot find the exact solution that I am looking for. I need a javascript code that when the user tries to exit the page, an alert box pops up with the "stay on page" or "leave page" options. If the user stays, it redirects them to another page and if they choose leave it leaves. Something similar to exit splash. I know this is poor practice but it is what the clients wants. Any help will be greatly appreciated. Thanks in advance for your help.
#main internet marketing discussion forum #javascript #redirect
  • I find Javascript a bit tricky at times but this resource may assist you: JavaScript - Page Redirection
    • [1] reply
    • Hey Benki,

      you use a javascrip popup and add a code on the page,
      if you want me to show you exactly you can pm me.
  • Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Click the button to display a confirm box.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <p id="warrior"></p>
    
    <script>
    function myFunction()
    {
    var x;
    var r=confirm("this is a pop up box");
    if (r==true)
      {
      x="You press the ok button";
      }
    else
      {
      x="You press the cancel button";
      }
    document.getElementById("demo").innerHTML=x;
    }
    </script>
    
    </body>
    </html>
    • [1] reply
    • Here you go, that's one option above.

      I had to use something else for squeeze pages
      otherwise it will popup without adding subscribers
      to the list, but if it is a regular page the one above
      is all you need.

Next Topics on Trending Feed

  • 5

    I have searched everywhere and I cannot find the exact solution that I am looking for. I need a javascript code that when the user tries to exit the page, an alert box pops up with the "stay on page" or "leave page" options. If the user stays, it redirects them to another page and if they choose leave it leaves. Something similar to exit splash. I know this is poor practice but it is what the clients wants. Any help will be greatly appreciated. Thanks in advance for your help.