几秒钟的延迟后,从一个站点重定向到另一个站点URL

时间:2018-07-24 16:41:21

标签: javascript html delay url-redirection

我有一个要求,即当最终用户访问siteurl时, https://myOld_SP2010_Site.com/sites/xyz 我想将他们重定向到我的新网站,例如 https://myNEW_SPO_Site.com/sites/xyz在旧网站首页停留几秒钟后。

如何做到这一点?尽管我尝试使用下面的代码引用HERE,但它在旧站点上停留的时间并不长:

<script>
    if(window.location.href == 'old_url')
   {
     window.location.href="new_url";
   }
</script>

1 个答案:

答案 0 :(得分:1)

window.onload = function(){
   if(window.location.href == "old_ulr"){
       redirectSite("new_url");
   }
};
function redirectSite(url){
   setTimeout(function(){window.location.href= url;}, 2000);
}