如何有条件地将引用人重定向到不同的网页

How do I conditionally redirect referrers to different webpages?

本文关键字:网页 重定向 有条件 引用      更新时间:2024-04-21

我正在为我的网站使用JavaScript"倒数然后重定向"脚本。我想在下面的脚本中使用类似http-referer的东西:

<script>
<!--
/*
Count down then redirect script
By JavaScript Kit (http://javascriptkit.com)
*/
//change below target URL to your own
var targetURL="www.domain.com";
//change the second to start counting down from
var countdownfrom=20;
var currentsecond = document.redirect.redirect2.value =
    countdownfrom + 1;
function countredirect() {
  if (currentsecond != 1) {
    currentsecond -= 1;
    document.redirect.redirect2.value = currentsecond
  } else {
    window.location = targetURL;
    return;
  }
  setTimeout(countredirect, 1000);
}
countredirect();
//-->
</script>

我希望脚本像一样工作

如果有人从www.twitter.com到达,他们将在倒计时后重定向到www.domain.com/twitter.html。

如果有人从www.facebook.com到达,他们将在倒计时后重定向到www.domain.com/facebook.html。

如果有人从www.youtube.com到达,他们将在倒计时后重定向到www.domain.com/youtube.html。

我想重定向15-20个URL。请帮忙!!我该怎么做??

简单:

var targetURL = /www'.xxx'.com/i.test(document.referrer) ?
    "www.domain-for-xxx.com" : "www.domain-for-yyy.com";

多个推荐人:

var targetUrl = "http://defaulturl.com/";
if (/www'.xxx'.com/i.test(document.referrer)) {
  targetUrl = "http://www.domain-for-xxx.com/";
} else if (/www'.yyy'.com/i.test(document.referrer)) {
  targetUrl = "http://www.domain-for-yyy.com/";
}
...