1

As someone completely new to javascript (my experience doesn't go past a mastery of CSS), can someone tell me if there is a way to add a delay to this exact redirect code by adding something into it, and can you pretty please show me how to do it as though I am an infant child who knows nothing because I am very, very inexperienced at javascript, and very, very confused.

<script>
  //redirect to new blog
  var path = window.location.pathname;
  window.location.replace('http://newurl.tumblr.com' + path);
</script>

All other questions on this topic seem require a stronger foundation of understanding of javascript than I have, or the code they're showing doesn't bear much resemblance to the one I'm using, and I find myself getting confused and lost when I read them. Questions like this one do have answers that seem simple enough, but since the new url is mentioned in the timeout code, I'm uncertain if that would effect the code I currently have, which I prefer because it redirects people to the corresponding pages of my blog instead of just to the homepage. Since that question and others like it confuse me that way, I'd appreciate any help with those concerns borne from my inexperience in mind!

Anthony
  • 36,459
  • 25
  • 97
  • 163

3 Answers3

4

You would do setTimeout()

Try this and see if it works for you:

<script>
  //redirect to new blog
  var path = window.location.pathname;
  setTimeout(function(){ 
      window.location.replace('http://belladxne.tumblr.com' + path);
  }, 3000);
</script>

If I'm understanding correctly...no, this code should not affect the URL replacement, since you're just grabbing the pathname of the current URL you are on.

kawnah
  • 3,204
  • 8
  • 53
  • 103
0

Combining your example code and the suggested answer from the linked question using setTimeout

<script>
  //delay in seconds:
  var redirectDelay = 5;

  //redirect to new blog
  var path = window.location.pathname;
  setTimeout(function() {
        window.location.replace('http://belladxne.tumblr.com' + path);
  }, redirectDelay * 1000);
</script>

I've also added the variable redirectDelay so that you can easily tweak the delay until you find the delay time that fits what you're wanting.

Anthony
  • 36,459
  • 25
  • 97
  • 163
0

here

setTimeout(function() {
    var path = window.location.pathname;
    window.location.replace('http://belladxne.tumblr.com' + path);
}, 2000); // <- this is the delay, 2 seconds
George_kane
  • 305
  • 3
  • 4
  • 17