...

View Full Version : JS timeout? ...



jmueller0823
03-16-2005, 11:05 PM
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:


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

Thanks.

codegoboom
03-17-2005, 12:35 AM
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...

jmueller0823
03-17-2005, 03:42 PM
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.


<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

codegoboom
03-17-2005, 03:47 PM
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.

jmueller0823
03-17-2005, 04:19 PM
* I'm new at this-- cut me some slack please :confused:

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!

codegoboom
03-17-2005, 04:38 PM
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:


<body onload="setTimeout(function(){document.getElementById('news').src='http://headlines.site.org/headlines/feed.js'}, 10000)">

jmueller0823
03-17-2005, 04:43 PM
Okay.

Only issue I see is formatting.

There are actually four of these lines inside a table, like this:
<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?

codegoboom
03-17-2005, 04:51 PM
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.

jmueller0823
03-17-2005, 05:04 PM
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.

codegoboom
03-17-2005, 05:12 PM
onload="setTimeout(function(){//commands go here... }, 10000)"

command#1:

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

3 to go...

jmueller0823
03-17-2005, 05:45 PM
Okay. It works, no errors at least.
If you would, please take a look at this. Does it look right?
<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.

codegoboom
03-17-2005, 05:53 PM
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...

jmueller0823
03-17-2005, 05:55 PM
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?

codegoboom
03-17-2005, 05:58 PM
Oh, I didn't look below the onload event... :D

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.

jmueller0823
03-17-2005, 06:06 PM
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.

codegoboom
03-17-2005, 06:14 PM
No, there would be no src="" attribute on any tag, in that scenario.

Your objective of allowing 10 seconds (from/until) is unclear... what do you mean, once again... this time, in as many words as possible. :D

jmueller0823
03-17-2005, 07:07 PM
Okay. First, here's the problem.

The js code and accompanying links, are newsfeeds. There are four of these. Each of these displays a text link to the news item.

Sometimes there is a delay with the feed that causes a an unacceptable delay on the page load time (while the page 'waits' for the js code to load).

Solution
So, let's say our maximum allowable load time for the js code is 10 seconds.
Therefore I'm thinking somehow we allow the js code to execute for 10 seconds. After 10 seconds, abort and allow the rest of the page to load.

Make sense?

codegoboom
03-17-2005, 07:30 PM
Maybe...

It might help to see the script's source code--to determine what could be done with its actions from your document, if anything.

But anyway, what all do the scripts do, exactly... insert one link each into the table?

If so, it would be possible to check for the created link by position every so often, and if non-existent, remove the src attribute to stop the script execution, and then reset it after a period of time, to reload/restart it... does that make sense?

jmueller0823
03-17-2005, 07:46 PM
But anyway, what all do the scripts do, exactly... insert one link each into the table?Yes.
This is the contents of headline1.js

document.write('Breaking Ranks -- African-American Pro-Family Leaders Pull Away from Left'); Probably not very helpful. :)

If so, it would be possible to check for the created link by position every so often, and if non-existent, remove the src attribute to stop the script execution, and then reset it after a period of time, to reload/restart it... does that make sense?Sure. I'm open to ideas.

Could you show me what you have in mind? Thanks.

codegoboom
03-17-2005, 07:58 PM
Oh, I see... wasn't paying much attention to the HTML, obviously. ;)

Just to make sure, is the source which you posted earlier definately what you'll be using?

jmueller0823
03-17-2005, 08:29 PM
Yes. I'll post it again, just to be sure
<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')[1].src='http://headlines.site.org/headlines/headline1.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[2].src='http://headlines.site.org/headlines/headline2.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[3].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/growthtrac/growthtrac1.asp">
<script src="http://headlines.site.org/headlines/headline1.js"></script>
</a><br>
<br>
<a href="http://headlines.site.org/users/growthtrac/growthtrac2.asp">
<script src="http://headlines.site.org/headlines/headline2.js"></script>
</a><br>
<br>
<a href="http://headlines.site.org/users/growthtrac/growthtrac3.asp">
<script src="http://headlines.site.org/headlines/headline3.js"></script>
</a></td>
</tr>
</table>
</body>
</html>

codegoboom
03-17-2005, 08:44 PM
Alright, now... can you tell me what difference it would make if you waited for the body to load before setting the sources? I can't see how any of this timing is really necessary, after all. :rolleyes:

jmueller0823
03-17-2005, 08:50 PM
can you tell me what difference it would make if you waited for the body to load before setting the sources?
Are you referring to your suggested code?

Well, let me ask you this:
If I'm understanding correctly, there is a ten second delay before the js loads...

So, what if then there is a delay at the newsfeed source (which is our problem). The page will still hang, waiting for the js display, right?

I guess I don't see how the onload delay makes a difference.
Maybe I'm missing something...

codegoboom
03-17-2005, 09:01 PM
If the problem is that of page-loading being delayed because the JS source files are causing said delay, then the only thing you can do is set those src properties after the page loads. There's no need for setTimeout, then... so change it to: <body onload="//commands...">

Did you have something else in mind?

jmueller0823
03-17-2005, 09:21 PM
ahhhh... I think I got it now.

So, if I remove the Timeout... it would look like this?
<body bgcolor="#FFFFFF"onload="{
document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='http://headlines.site.org/headlines/timedate1.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[1].src='http://headlines.site.org/headlines/headline1.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[2].src='http://headlines.site.org/headlines/headline2.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[3].src='http://headlines.site.org/headlines/headline3.js';
}">

<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/growthtrac/growthtrac1.asp">
<script src="http://headlines.site.org/headlines/headline1.js"></script>
</a><br>
<br>
<a href="http://headlines.site.org/users/growthtrac/growthtrac2.asp">
<script src="http://headlines.site.org/headlines/headline2.js"></script>
</a><br>
<br>
<a href="http://headlines.site.org/users/growthtrac/growthtrac3.asp">
<script src="http://headlines.site.org/headlines/headline3.js"></script>
</a></td>
</tr>
</table>
And the Table code (above) is okay as is?

codegoboom
03-17-2005, 09:31 PM
Delete every src="" attribute for every script tag in the table, or at least, the URL's inside them, and get rid of "{" "}" those. :)

jmueller0823
03-17-2005, 09:34 PM
Correct?
<body bgcolor="#FFFFFF"onload="
document.getElementById('news').getElementsByTagName('SCRIPT')[0].src='http://headlines.site.org/headlines/timedate1.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[1].src='http://headlines.site.org/headlines/headline1.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[2].src='http://headlines.site.org/headlines/headline2.js';
document.getElementById('news').getElementsByTagName('SCRIPT')[3].src='http://headlines.site.org/headlines/headline3.js';
">

<table id="news" width="147" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="147" class="xsmall">
<script http://headlines.site.org/headlines/timedate1.js></script>
<br>
<a href="http://headlines.site.org/users/growthtrac/growthtrac1.asp">
<script http://headlines.site.org/headlines/headline1.js></script>
</a><br>
<br>
<a href="http://headlines.site.org/users/growthtrac/growthtrac2.asp">
<script http://headlines.site.org/headlines/headline2.js></script>
</a><br>
<br>
<a href="http://headlines.site.org/users/growthtrac/growthtrac3.asp">
<script http://headlines.site.org/headlines/headline3.js></script>
</a></td>
</tr>
</table>

codegoboom
03-17-2005, 09:35 PM
Are you kidding? :D

jmueller0823
03-17-2005, 09:39 PM
"kidding" about...?

codegoboom
03-17-2005, 09:42 PM
I forget... just go ahead and run with it. ;)

jmueller0823
03-17-2005, 09:54 PM
Okay.

Just tried the code. No errors, but the js feeds do not display.
Do me a favor pls... how does the code look to you?

Thanks.

codegoboom
03-17-2005, 10:04 PM
Actually, there's no solution to your problem, short of changing the newsfeed code... I'm a little absent-minded today. :cool:

jmueller0823
03-17-2005, 10:06 PM
Ahhh. So you've been pulling my chain all day? :)

codegoboom
03-17-2005, 10:54 PM
I can't remember... :D

Technically, it would be possible to get around the loading issue by reading the js files, extracting their text, and using a different method to place it, if you can believe it... (just don't ask me how). ;)

jmueller0823
03-17-2005, 10:55 PM
Thanks for the effort.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum