Skip to content Skip to sidebar Skip to footer

How To Redirect Page And Js Using Javascript On External Domain Based On Referer?

I have some sites mysite1.com, mysite2.com,....mysiten.com All mysite1-n.com using external javascript on myexternalsite.com/mainfile.js I want, if (mysite1-n.com) visitors come fr

Solution 1:

basically you should check for document.referrer value and the document.location.href to do achieve what you want. This with a bunch of regexp should do the trick easily.

ex:

if( document.location.href.match(/^https?:\/\/mysite1-n.com/) ){
  if( document.referrer.match(/google.com/) ){
    window.location = 'http://welcome.com';
  }
  var s = document.createElement('script');
  s.src = 'myexternalsite.com/mainfile.js';
  document.head.appendChild(s);
}

and so on

Post a Comment for "How To Redirect Page And Js Using Javascript On External Domain Based On Referer?"