SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Jul 20, 2001, 17:54 #1
- Join Date
- Jul 2001
- Location
- Vancouver, WA
- Posts
- 23
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can I force a script to timeout if it doesn't execute immediately
In the body of my web page there is a call to a javascript residing on another server. If there is a problem with the server containing the javascript, then my web page won't load until it times out after about a minute or so. I would like to be able to force the javascript to time out if it doesn't load in a specified amount of time (say 5 seconds). Can this be done...and if so, how do I do it?
Thanks guys.
-
Jul 22, 2001, 10:31 #2
- Join Date
- Jun 2001
- Location
- rollin' on dubs
- Posts
- 492
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi,
my javascript book is at the office, so i can't post an answer to your timeout question. however, i have had a lot of success with try/catch statements:
<script language="javasctipt">
try {
this would be where your function call will go. if any thing fails, that actions in your catch statement will execute.
}
catch(e) {
this is where the you would put your code to dynamically change your timeout, or whatever else you would like to have happen if your main function fails. The "e" parameter is the error object, so this could also be where you insert error handling. ex. document.write(e.description); will write out what type of error has occured
}
</script>
Does that help? Let me know if I can clarify this at all. Try/catch statements are also used with Java for error handling.
-
Jul 22, 2001, 11:45 #3
- Join Date
- Jul 2001
- Location
- Vancouver, WA
- Posts
- 23
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here is the code I was referring to with the javascript call:
<td width="100%">
<FONT CLASS="Verse">
<script src="http://www.verseoftheday.com/kjvverse.js"></script>
</FONT>
</td>
-
Jul 23, 2001, 11:02 #4
-
Jul 23, 2001, 11:30 #5
- Join Date
- Jul 2001
- Location
- Vancouver, WA
- Posts
- 23
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A couple days ago I tried to open my homepage but it took about a minute or two to open because it was trying to access that javascript (Bible verse of the day) which is provided by another company on their servers. Because their site was down mine had to wait until the script timed out before it would continue to open the rest of my page. All I would like to be able to do is tell it to skip past that javascript if it doesn't open within a few seconds. I'm not a javascript expert so I don't know if this can be done or not.
-
Jul 23, 2001, 11:35 #6
-
Jul 24, 2001, 15:33 #7
- Join Date
- Jun 2001
- Location
- rollin' on dubs
- Posts
- 492
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hey,
i don't know why this didn't occur to me sooner. first of all, I know that these try/catch statements are supported by IE 5.5 but I don't know what support is like with other browsers.
Anyway, this should work.
<html>
<head>
<script src="http://www.verseoftheday.com/kjvverse.js"></script>
</head>
<body>
<script language="javascript">
try{
bibleVerseOfTheDayFunction();
}
catch(e) {
document.write("Javascript link not working.")
}
</script>
</body>
</html>
I am a bit perplexed as to what caused your problem. If your site can't access the server where your javascript functions are stored, it shouldn't make you wait, it should give you one of those javascript alert boxes saying that it doesn't recognize the function that you're calling. If there is more to it with the timeouts, then this might not work and I would be stumped.
Good Luck.
-
Jul 24, 2001, 15:36 #8
- Join Date
- Jul 2001
- Location
- Vancouver, WA
- Posts
- 23
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks makeda...I'll give it a try
Bookmarks