1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Exit Redirect Plugin/Script time controlled

Discussion in 'Scripting' started by amz1337, Apr 7, 2017.

  1. amz1337

    amz1337 Newbie

    Joined:
    Feb 24, 2014
    Messages:
    1
    Likes Received:
    0
    Hello everybody,

    I searched the whole Internet, unfortunately I find no solution.

    My situation: Im working with Wordpress + OptimizePress.
    Im searching for a plugin or a simple script which allows me to redirect users to different sites, when they try to exit the site BUT it has to be time controlled.
    Example:

    USER 1 opens my site. He trys to leave after 10 seconds -> He gets the standart browser pop up and if he clicks on "stay" he is redirected to PAGE A

    USER 2 opens my site. He trys to leave after 60 seconds (!) -> He gets the standart browser pop up and if he clicks on "stay" he is redirected to PAGE B

    You see, I would like the users to be redirected to different pages on the basis of their visittime.

    If there is any script or any plugin or advice you would help me very much.

    Thank you in advance
     
  2. Captain America

    Captain America Newbie

    Joined:
    Apr 8, 2017
    Messages:
    24
    Likes Received:
    8
    Gender:
    Male
    i don't know of a plugin but here is how you'd do it in javascript: (add this to the head section of the page you want the redirect on)

    Code:
    <script>
    var url ='http://url1.html';
    var timestamp  = Math.floor(Date.now() / 1000);
    
    window.onbeforeunload = function(){
    
    var timestamp_now  = Math.floor(Date.now() / 1000);
    
    if ( timestamp_now -  timestamp > 60)
    {
       var url ='http://url2.html';
    }
    
    if(confirm('are you sure to exit?'))
               return true;
          else
               window.location=url;
    };
    </script>