0

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 from www.google.com then will redirect to welcome.com

if (mysite1-n.com) visitors come from www.yahoo.com then will redirect to welcome2.com

if (mysite1-n.com) visitors come from www.anotherdomain.com then will call javascript on myexternalsite.com/file1.js and working using this script

And if (mysite1-n.com) visitors come from bookmark then will call javascript on myexternalsite.com/file2.js and working using this script

What sort of script should I be using on myexternalsite.com/mainfile.js ?

Thank's

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

thank's, but I'm very stupid in javascript... Can you make for me the script ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.