如何在基于referer的外部域上使用javascript重定向页面和js?

如何在基于referer的外部域上使用javascript重定向页面和js?,javascript,redirect,external,referer,Javascript,Redirect,External,Referer,我有一些网站mysite1.com,mysite2.com,…mysiten.com 所有mysite1-n.com在myexternalsite.com/mainfile.js上使用外部javascript 我要 如果(mysite1-n.com)访问者来自www.google.com,则将重定向到welcome.com 如果(mysite1-n.com)访问者来自www.yahoo.com,则将重定向到welcome2.com 如果(mysite1-n.com)访问者来自www.anothe

我有一些网站
mysite1.com
mysite2.com
,…
mysiten.com

所有
mysite1-n.com
myexternalsite.com/mainfile.js上使用外部javascript

我要

如果(
mysite1-n.com
)访问者来自
www.google.com
,则将重定向到
welcome.com

如果(
mysite1-n.com
)访问者来自
www.yahoo.com
,则将重定向到
welcome2.com

如果(
mysite1-n.com
)访问者来自
www.anotherdomain.com
,则将调用
myexternalsite.com/file1.js上的javascript并使用此脚本

如果(
mysite1-n.com
)访问者来自书签,那么将调用
myexternalsite.com/file2.js
上的javascript并使用此脚本

我应该在
myexternalsite.com/mainfile.js
上使用哪种脚本


谢谢

基本上,您应该检查document.referer值和document.location.href以实现您的目标。这与一堆regexp应该很容易做到这一点

例:


等等

谢谢,但我在javascript方面很笨。。。你能帮我做剧本吗?
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);
}