#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0

    Redirect to a website after limited page view of a website.


    I have a website well indexed in Google. I want to redirect my viewer to a new website which I have created now. I want to use a cookies based programming, so that viewer will autometically redirected to my new website when they visits more than 10 pages of my website.

    I use this code for redirect after 10 seconds.


    <html>
    <head>
    <script type="text/javascript">
    <!--
    function Redirect() {
    window.location="URL address";
    }
    document.write("You will be redirected to our main page in 10 seconds!");
    setTimeout('Redirect()', 10000);
    //-->
    </script>
    </head>
    <body>
    </body>
    </html>
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,041
    Rep Power
    119
    Not quit sure why you want your visitor to view 10 pages of your old website; before being redirected to your new website..., but anyway... here ya go:

    Code:
    <script>
    
    var maxHits = 10;
    
    var newSiteURL="http://www.yahoo.com";
    
    function Redirect()
    {
    window.location.replace(newSiteURL);
    }
    
    function clearStorage()
    {
    window.localStorage.clear();
    }
    
    function checkHit()
    {
    
    if(typeof(Storage)!=="undefined")
     {
     if (localStorage.hitcount)
      {
       localStorage.hitcount = Number(localStorage.hitcount) + 1;
      }
     else
      {
       localStorage.hitcount = 1;
      }
     }
    
    if (localStorage.hitcount >= maxHits) {
      var message = document.createElement("div");
      message.style.padding = 50 + "px";
      message.style.border="solid 2px #ff0000";
      message.style.textAlign="center";
      message.style.backgroundColor="#FFF";
      message.style.color="#ff0000";
      message.style.position="fixed";
      message.style.top = 25 + "px";
      message.style.left = 25 + "px";
      message.style.zIndex="777";
      message.style.fontWeight="bold";
      message.innerHTML="You will be redirected to our main page in 10 seconds!";
      document.getElementsByTagName("body")[0].appendChild(message);
      setTimeout("Redirect()",10000);
      clearStorage();
    }
    
    }
    
    window.onload = function() {
    checkHit();
    }
    
    </script>
    Last edited by web_loone08; February 8th, 2013 at 09:49 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0
    This code is working nicely, Thanks a lot to web_loone08

IMN logo majestic logo threadwatch logo seochat tools logo