Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-16-2005, 10:05 PM   PM User | #1
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
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.
jmueller0823 is offline   Reply With Quote
Old 03-16-2005, 11:35 PM   PM User | #2
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
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*
codegoboom is offline   Reply With Quote
Old 03-17-2005, 02:42 PM   PM User | #3
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
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
jmueller0823 is offline   Reply With Quote
Old 03-17-2005, 02:47 PM   PM User | #4
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
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.
__________________
*this message will self destruct in n-seconds*

Last edited by codegoboom; 03-17-2005 at 03:17 PM.. Reason: ?
codegoboom is offline   Reply With Quote
Old 03-17-2005, 03:19 PM   PM User | #5
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
* 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!
jmueller0823 is offline   Reply With Quote
Old 03-17-2005, 03:38 PM   PM User | #6
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
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*
codegoboom is offline   Reply With Quote
Old 03-17-2005, 03:43 PM   PM User | #7
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
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 05:50 PM..
jmueller0823 is offline   Reply With Quote
Old 03-17-2005, 03:51 PM   PM User | #8
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
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*
codegoboom is offline   Reply With Quote
Old 03-17-2005, 04:04 PM   PM User | #9
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
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.
jmueller0823 is offline   Reply With Quote
Old 03-17-2005, 04:12 PM   PM User | #10
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
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*
codegoboom is offline   Reply With Quote
Old 03-17-2005, 04:45 PM   PM User | #11
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
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 05:51 PM..
jmueller0823 is offline   Reply With Quote
Old 03-17-2005, 04:53 PM   PM User | #12
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
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*
codegoboom is offline   Reply With Quote
Old 03-17-2005, 04:55 PM   PM User | #13
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
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?
jmueller0823 is offline   Reply With Quote
Old 03-17-2005, 04:58 PM   PM User | #14
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
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*
codegoboom is offline   Reply With Quote
Old 03-17-2005, 05:06 PM   PM User | #15
jmueller0823
New Coder

 
Join Date: Mar 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
jmueller0823 is an unknown quantity at this point
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

Quote:
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.
jmueller0823 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Advertisement
Log in to turn off these ads.