Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to delay window.location.href?

    I guess this is an easy question for all javascripters but I don't know how to manage (I'm pretty fresh with JS). I found two solutions on this forum but it seems that they don't work(?).

    I want to delay for few seconds window.location.href="destination_site.html" before it will automatically take visitor to destination site. It has something to do with setTimeout but I would be greatful for posting a fixed code.

    Thanks in advance.

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    i this on click or on load?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Well, whether onclick or onload, the answer's really the same:

    If
    Code:
    window.location.href="destination_site.html"
    is working where it is, now, without the delay, then just use
    Code:
    setTimeout('window.location.href="destination_site.html"', 5000) /* 5 seconds */
    Now, *if* that is indeed inline in something like
    Code:
    <body onload='window.location.href="destination_site.html"'>
    or
    Code:
    <input type="button" onclick='window.location.href="destination_site.html"'>
    Then it's trickier. Example:
    Code:
    <body onload='setTmeout("window.location.href=\"destination_site.html\"",5000)'>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That works very good. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •