如何在外部网站上基于引荐来源使用javascript重定向页面和js? [英] How to redirect page and js using javascript on external domain based on referer?
问题描述
我有一些站点mysite1.com
,mysite2.com
,.... mysiten.com
I have some sites mysite1.com
, mysite2.com
,....mysiten.com
所有mysite1-n.com
在myexternalsite.com/mainfile.js
我想要
如果(mysite1-n.com
)位访问者来自www.google.com
,则将重定向到welcome.com
if (mysite1-n.com
) visitors come from www.google.com
then will redirect to welcome.com
如果(mysite1-n.com
)位访问者来自www.yahoo.com
,则将重定向到welcome2.com
if (mysite1-n.com
) visitors come from www.yahoo.com
then will redirect to welcome2.com
如果(mysite1-n.com
)位访问者来自www.anotherdomain.com
,则将在myexternalsite.com/file1.js
上调用javascript并使用此脚本进行工作
if (mysite1-n.com
) visitors come from www.anotherdomain.com
then will call javascript on myexternalsite.com/file1.js
and working using this script
如果(mysite1-n.com
)位访问者来自书签,则将在myexternalsite.com/file2.js
上调用javascript并使用此脚本进行工作
And if (mysite1-n.com
) visitors come from bookmark then will call javascript on myexternalsite.com/file2.js
and working using this script
我应该在myexternalsite.com/mainfile.js
上使用哪种脚本?
What sort of script should I be using on myexternalsite.com/mainfile.js
?
谢谢
推荐答案
基本上,您应该检查document.referrer值和document.location.href来实现所需的功能.带有一堆正则表达式可以轻松解决问题.
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.
例如:
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);
}
以此类推
这篇关于如何在外部网站上基于引荐来源使用javascript重定向页面和js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!