[英]How to redirect page and js using javascript on external domain based on referer?
I have some sites mysite1.com
, mysite2.com
,.... mysiten.com
我有一些网站mysite1.com
, mysite2.com
,.... mysiten.com
All mysite1-n.com
using external javascript on myexternalsite.com/mainfile.js
使用mysite1-n.com
外部JavaScript的所有myexternalsite.com/mainfile.js
I want, 我想要,
if ( mysite1-n.com
) visitors come from www.google.com
then will redirect to welcome.com
如果( mysite1-n.com
)访问者来自www.google.com
则将重定向到welcome.com
if ( mysite1-n.com
) visitors come from www.yahoo.com
then will redirect to welcome2.com
如果( mysite1-n.com
)访问者来自www.yahoo.com
则将重定向到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 如果( mysite1-n.com
)访问者来自www.anotherdomain.com
则将在myexternalsite.com/file1.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 如果( mysite1-n.com
)访问者来自书签,则将在myexternalsite.com/file2.js
上调用javascript并使用此脚本进行工作
What sort of script should I be using on myexternalsite.com/mainfile.js
? 我应该在myexternalsite.com/mainfile.js
上使用哪种脚本?
Thank's 谢谢
basically you should check for document.referrer value and the document.location.href to do achieve what you want. 基本上,您应该检查document.referrer值和document.location.href以实现所需的功能。 This with a bunch of regexp should do the trick easily. 这与一堆regexp应该可以轻松实现。
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 等等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.