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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 35

Thread: JS timeout? ...

  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS timeout? ...

    We display newsfeeds via JS from an outside source.

    Sometimes those feeds are delayed or unavailable and that delays the page load time.

    (The host tells me they have a built in time-out, but we still experience these issues.)

    So... is there a way to install our own "time-out" code?
    The JS looks like this:

    Code:
    <script src="http://headlines.site.org/headlines/feed.js"></script>
    We have a php site.

    Thanks.

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know what you mean, exactly, but a function can be re-called every so often (until some condition is met), using window.setTimeout...
    *this message will self destruct in n-seconds*

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll explain further.

    Since that code (provided by a newsfeed source) sometimes is very slow or unresponsive, I want to put a time limit on it.

    Code:
    <a href="http://headlines.site.org/users/mysite/link.asp"> 
          <script src="http://headlines.site.org/headlines/headline2.js"></script>
    In other words, I'd like to give the above code about 10 seconds to display. How would I do that?

    Thanks.
    Jim

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    10 seconds to display what?

    ... if you mean a delay for setting the source, then give the script an id, and use setTimeout w/ onload to set its 'src' property.
    Last edited by codegoboom; 03-17-2005 at 04:17 PM. Reason: ?
    *this message will self destruct in n-seconds*

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    * I'm new at this-- cut me some slack please

    I'm thinking that I need to 'expose" the code for 10 seconds (or whatever)--
    How would I do that?

    (The js code displays a newsfeed link)

    Thanks!

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, try removing the src attribute from the script tag, give it an id attribute (id="news"), and then set it on load; for example:

    Code:
    <body onload="setTimeout(function(){document.getElementById('news').src='http://headlines.site.org/headlines/feed.js'}, 10000)">
    *this message will self destruct in n-seconds*

  • #7
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay.

    Only issue I see is formatting.

    There are actually four of these lines inside a table, like this:
    Code:
    <table width="147" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td width="147" class="xsmall"> 
          <script src="http://headlines.site.org/headlines/timedate1.js"></script>
          <br>
          <a href="http://headlines.site.org/users/1.asp"> 
          <script src="http://headlines.site.org/headlines/headline1.js"></script>
          </a><br>
          <br>
          <a href="http://headlines.site.org/users/2.asp"> 
          <script src="http://headlines.site.org/headlines/headline2.js"></script>
          </a><br>
          <br>
          <a href="http://headlines.site.org/users/3.asp"> 
          <script src="http://headlines.site.org/headlines/headline3.js"></script>
          </a></td>
      </tr>
    </table>
    Do-able?
    Last edited by jmueller0823; 03-23-2005 at 06:50 PM.

  • #8
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes... give the table the "news" id, and use document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='whatever.js'; //etc. through ...[3].src='whatever.js' to set each property.
    *this message will self destruct in n-seconds*

  • #9
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need a little more detail (I'm new at this)... Thanks.

    Are you saying use the 'body onload' stuff to load the table?

    Assuming that...

    The table would look like:
    <table id="news" width="147" border="0" cellspacing="0" cellpadding="0">
    Right?

    And please tell me more about the body code.

  • #10
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    onload="setTimeout(function(){//commands go here... }, 10000)"

    command#1:

    document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='whatever.js';

    3 to go...
    *this message will self destruct in n-seconds*

  • #11
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay. It works, no errors at least.
    If you would, please take a look at this. Does it look right?
    Code:
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body bgcolor="#FFFFFF"onload="setTimeout(function(){document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='http://headlines.site.org/headlines/timedate1.js';
     document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='http://headlines.site.org/headlines/headline1.js';
     document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='http://headlines.site.org/headlines/headline2.js';
     document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='http://headlines.site.org/headlines/headline3.js';
      }, 10000)">
    
    
    <table id="news" width="147" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td width="147" class="xsmall"> 
          <script src="http://headlines.site.org/headlines/timedate1.js"></script>
          <br>
          <a href="http://headlines.site.org/users/1.asp"> 
          <script src="http://headlines.site.org/headlines/headline1.js"></script>
          </a><br>
          <br>
          <a href="http://headlines.site.org/users/2.asp"> 
          <script src="http://headlines.site.org/headlines/headline2.js"></script>
          </a><br>
          <br>
          <a href="http://headlines.site.org/users/3.asp"> 
          <script src="http://headlines.site.org/headlines/headline3.js"></script>
          </a></td>
      </tr>
    </table>
    </body>
    </html>
    Thanks.
    Last edited by jmueller0823; 03-23-2005 at 06:51 PM.

  • #12
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just about... you may want to number the corresponding references sequentially [0], [1], [2], etc.

    --of course a loop would be more 'efficient', but as long as it works, right...
    *this message will self destruct in n-seconds*

  • #13
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So, as I'm learning how this works...

    Are we 'testing' the js feeds in the onload section?
    Then, is it passes, go to the table?

  • #14
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, I didn't look below the onload event...

    No, you should remove the src attributes from the script tags, if the whole point was to load them after 10 seconds--that's what the function would do, indirectly, by setting those src properties.
    *this message will self destruct in n-seconds*

  • #15
    New Coder
    Join Date
    Mar 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So, the js lines in the table should be changed from this:

    <script src="http://headlines.site.org/headlines/timedate1.js"></script>

    to this?

    http://headlines.site.org/headlines/timedate1.js

    if the whole point was to load them after 10 seconds
    Ugh! I hope we're understanding each other.

    My objective is to allow 10 seconds for the load.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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