Results 1 to 7 of 7

Thread: javascript timeout

  1. #1
    Join Date
    Aug 2013
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript timeout

    I have a form that redirects to a site if its online or print error message if its online.

    Now I want to delay and redirect to the site whether offline or online after 5 seconds elapse.

    I have added setTimeout() but it does not delay for 5 minutes before redirecting to another site.

    Any help

    Code:
    <script type="text/javascript">
    //start checking onlineconnection status
    function checkconnection() {
    
    var status = navigator.onLine;
    if (status) {
    
    window.onload=timeout;
    function timeout(){
    window.setTimeout("redirect()",5000)}
    
    
    
    window.location="www.online.com"
    
    
    
    } else {
    
    window.location="www.offline.com"
    }
    }
    </script>
    on the body, i have onload() event
    Code:
    <body onload="checkconnection();">
    Any Help

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    This is not a php issue, you're asking about javascript. You need to ask in the proper forum.
    You never know everything, I learn everyday!

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Thread moved.

    Quote Originally Posted by mutago View Post
    I have a form that redirects to a site if its online or print error message if its online.
    Your example code does not seem to attempt this: looks like it intends to redirects to one site if online, and to a different site if offline.

    Quote Originally Posted by mutago View Post
    Now I want to delay and redirect to the site whether offline or online after 5 seconds elapse.
    I have added setTimeout() but it does not delay for 5 minutes before redirecting to another site.
    What does it do?

    One thing I notice right away is that you specify a callback in setTimeout named redirect, but your code defines no such function.

    Also note that onLine is not the most reliable of properties. It works differently, and means different things, in different browsers. You might want to read this article for more ideas about working online/offline (for example, checking via AJAX or listening to the AppCache error event).

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,138
    Thanks
    44
    Thanked 3,231 Times in 3,192 Posts
    Blog Entries
    12

    Default

    Your post is very confusing:

    redirects to a site if its online or print error message if its online.
    It can't do both. And:

    Now I want to delay and redirect to the site whether offline or online after 5 seconds elapse.

    I have added setTimeout() but it does not delay for 5 minutes before redirecting to another site.
    "the site" - which site(s) do you mean, and is it minutes or seconds you want?

    Please restate your question in a clearer fashion.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Aug 2013
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you. i want to check if internet connection is available and then delay for about 5 seconds before redirecting to onlinesite.com and if internet connection is not available then delay for about 5 seconds before redirecting to eg. offlinesite.com

    thank you

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    The confusing part is why you would try to redirect (anywhere) if the user was offline.

  7. #7
    Join Date
    Aug 2013
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    am not redirecting anywhere. okay just consider the offlinesite.com to be offline.html and onlinesite.com to be online.html

    thanks

Similar Threads

  1. Timeout renew
    By ronchan in forum PHP
    Replies: 0
    Last Post: 01-09-2010, 07:06 AM
  2. Session Timeout
    By fg123 in forum PHP
    Replies: 4
    Last Post: 08-06-2009, 06:51 PM
  3. Resolved Need timeout help
    By nycguurl in forum JavaScript
    Replies: 9
    Last Post: 06-04-2009, 11:26 PM
  4. timeout alert
    By hantz in forum JavaScript
    Replies: 3
    Last Post: 11-10-2007, 09:29 AM
  5. Session Timeout
    By kaizen in forum JavaScript
    Replies: 1
    Last Post: 11-30-2005, 08:09 AM

Bookmarks

Posting Permissions

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