SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Member
    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.

  2. #2
    ********* obeah makeda's Avatar
    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.

  3. #3
    SitePoint Member
    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>

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm sorry but i am still not following what you want to do. if the server which contains your javascript file is offline, what do you want to have happen?

  5. #5
    SitePoint Member
    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.

  6. #6
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got ya. let me think about this one and get back to you.

  7. #7
    ********* obeah makeda's Avatar
    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.

  8. #8
    SitePoint Member
    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

Posting Permissions

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