Enjoy an ad free experience by logging in. Not a member yet?
Register .
03-16-2005, 10:05 PM
PM User |
#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.
03-16-2005, 11:35 PM
PM User |
#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*
03-17-2005, 02:42 PM
PM User |
#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
03-17-2005, 02:47 PM
PM User |
#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.
__________________
*this message will self destruct in n-seconds*
Last edited by codegoboom; 03-17-2005 at 03:17 PM ..
Reason: ?
03-17-2005, 03:19 PM
PM User |
#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!
03-17-2005, 03:38 PM
PM User |
#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*
03-17-2005, 03:43 PM
PM User |
#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 05:50 PM ..
03-17-2005, 03:51 PM
PM User |
#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*
03-17-2005, 04:04 PM
PM User |
#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.
03-17-2005, 04:12 PM
PM User |
#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*
03-17-2005, 04:45 PM
PM User |
#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 05:51 PM ..
03-17-2005, 04:53 PM
PM User |
#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*
03-17-2005, 04:55 PM
PM User |
#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?
03-17-2005, 04:58 PM
PM User |
#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*
03-17-2005, 05:06 PM
PM User |
#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
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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 02:09 PM .
Advertisement
Log in to turn off these ads.