Coding question

by 6 replies
7
Hi warriors,

I have set up a wordpress blog and am looking for a piece of code, piece of software or possibly even a wordpress plugin that will allow me to do the following:

When a user closes their browser or presses the back button on their browser I want them to be redirected to another page with a message that asks whether they would like to leave or stay on the page. For example purposes, the following site has this property - Backlink Profit Monster - Powerful Link Building Software.

Anyone know how this can be achieved? Any replies would be really appreciated.

Thanks,
Ali
#programming #coding #question
  • I found this

    Code:
    <script language="JavaScript">
      var needToConfirm = true;
      
      window.onbeforeunload = confirmExit;
      function confirmExit()
      {
        if (needToConfirm)
          return "Are you sure you want to exit this page?";
    window.location="link";
      }
    </script>
    Just google search if you want to find other scripts that do more for you.
    • [1] reply
    • Thanks for the speedy reply.

      I actually found this exact code when I ran a google search myself. Having tried it out, it does display a message asking whether the user wants to stay on the page but unfortunately does not redirect them to another page at the same time like the example page above.

      I searched a few times on google and couldn't find anything that managed to do both of these things simultaneously.

      Do you, or any other warriors, have a piece of code that can do this?
  • I'm pretty sure that if the user closes their browser or presses the back button, it means that the user wants to leave.
    • [2] replies
    • Haha, true.

      But anyways, heres the code

      Code:
      <script>window.onbeforeunload = function(){
              location.assign('http://www.google.com');
              return "go to google instead?";
          }
      </script>
      Make sure you leave the return line with a short message

      I tested this and used it in the <body> tags
      • [ 1 ] Thanks
    • Haha, if they're that intent on leaving then they'll ignore the offer that I'm giving them and click on 'leave the page' when it appears. I'm sure you've seen this code used by marketers before.

      Fantastic! Thats just what I needed.

      Really appreciate the help.
      • [1] reply

Next Topics on Trending Feed

  • 7

    Hi warriors, I have set up a wordpress blog and am looking for a piece of code, piece of software or possibly even a wordpress plugin that will allow me to do the following: