Skip to content Skip to sidebar Skip to footer

Redirect Based On Referrer Url

In my site I have a password protected page containing some links to other sites also operated by myself that cannot be password protected. I would like to place a HTML code onto o

Solution 1:

if (document.referrer !== "http://www.stackoverflow.com") {
    window.location.href = "http://www.google.com";
}

Or you can use regular expressions to check the referrer.

Anyway, this solution is really, really unsafe. You can just turn off JavaScript in your browser and won't be redirected...

Solution 2:

Try this

functionurl(url){
      return url.match(/:\/\/(.[^/]+)/)[1];
    }

    functioncheck()
    {
      var ref = document.referrer;
      if(url(ref) =='www.google.com')
      {
          // do something
      }
      else
      {
         // redirectwindow.location.href = 'http://yourDomain.com';
      }
   }

Solution 3:

I found document.referrer doesn't work for me, but location.href works:

if (location.href != "http://yoursite/index.html") {
    location.replace("http://yoursite/index.html");
}

Post a Comment for "Redirect Based On Referrer Url"