-1

I have a requirement, wherein when endusers access a siteurl say , https://myOld_SP2010_Site.com/sites/xyz i would like to redirect them my new site, say https://myNEW_SPO_Site.com/sites/xyz after staying on the old site home page for few seconds.

How this can be achieved? though i tried the below code refer HERE , it is not staying for a few seconds on the old site :

<script>
    if(window.location.href == 'old_url')
   {
     window.location.href="new_url";
   }
</script>
samolpp2
  • 139
  • 1
  • 13
  • Possible duplicate of [time delayed redirect?](https://stackoverflow.com/questions/9877263/time-delayed-redirect) – Nope Jul 24 '18 at 16:45
  • 1
    use setTimeout, https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout – Adam H Jul 24 '18 at 16:45
  • also if you don't NEED the JavaScript it can be done in a tag -> https://stackoverflow.com/questions/3292038/redirect-website-after-certain-amount-of-time – daddygames Jul 24 '18 at 16:46
  • @daddygames - Seems the linked post also mentions that the refresh tag is deprecated. https://en.wikipedia.org/wiki/Meta_refresh also mentions it is not part of the HTTP standard but lists some alternatives. Interestingly they don't recommend the JavaScript alternative in case a browser has it disabled,.. though OP already uses it so I assume OP is targeting JS enabled browsers. – Nope Jul 24 '18 at 16:52
  • am sorry, if there is an already answer for the same requirement.my request to Please do not downgrade my question. – samolpp2 Jul 24 '18 at 16:55
  • @SaMolPP In general that is exactly one of the reasons one might downvote. The tooltip on the downvote icon even says *Shows no research effort* - Though it is based on opinions what is considered no research effort off course :/ I wouldn't worry too much. If I mess up a search and get downvoted for being blind I usually end up deleting my question and go to the marked duplicates. – Nope Jul 24 '18 at 16:59
  • @Nope according to W3Schools, all modern browsers support the meta tag for redirecting. W3C recommends not using it for various reasons, but as long as you address the concerns they list, it should be fine. https://www.w3schools.com/Tags/att_meta_http_equiv.asp – daddygames Jul 24 '18 at 18:24
  • W3C -> https://www.w3.org/TR/WCAG10-HTML-TECHS/#meta-element – daddygames Jul 24 '18 at 18:24

1 Answers1

1
window.onload = function(){
   if(window.location.href == "old_ulr"){
       redirectSite("new_url");
   }
};
function redirectSite(url){
   setTimeout(function(){window.location.href= url;}, 2000);
}
Chuck Okeh
  • 11
  • 3