Please help me about Javascript redirect

4 replies
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.
#javascript #redirect
  • Profile picture of the author David Braybrooke
    I find Javascript a bit tricky at times but this resource may assist you: JavaScript - Page Redirection
    Signature
    "The scientific theory I like best is that the rings of Saturn are composed entirely of lost airline luggage." - Mark Russell
    {{ DiscussionBoard.errors[9037886].message }}
    • Profile picture of the author Dani78
      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.
      Signature
      57 FREE Traffic Sources >> Download Here
      {{ DiscussionBoard.errors[9042669].message }}
  • 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>
    {{ DiscussionBoard.errors[9042680].message }}
    • Profile picture of the author Dani78
      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.
      Signature
      57 FREE Traffic Sources >> Download Here
      {{ DiscussionBoard.errors[9046971].message }}

Trending Topics