Forum Moderators: open

Message Too Old, No Replies

Timeout after time

How?

         

xcandyman

12:17 pm on Dec 9, 2002 (gmt 0)

10+ Year Member



Hi all

I have a iframe page which calls an external website to get code. Im a little worried if that site goes down for a period of time and my page wont load correctly.

Is it possible to set a timeout period for that iframe to say in 10 seconds and if the page is not loaded, a local html page loads in that Iframe saying temp unavailable?

Thanks

Steve

korkus2000

1:02 pm on Dec 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think javascript will be able to know if the page loaded or not. If you set up a timeout script it will execute no matter what. AFAIK, I don't think it is possible client side, especially since you don't have control over the page being loaded. I am pretty sure there is a server-side solution, probably checking the header code.

xcandyman

1:40 pm on Dec 9, 2002 (gmt 0)

10+ Year Member



I do have control over the iframe page because I created it. Im not very techy when it comes to scripting and servers.

Any help will be greatly appreciated

Thanks

Steve

lorax

5:41 pm on Dec 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use the onLoad event to mark the succesful loading of a Window object or frame object. I'm not sure if iFrames qualify as a frame object but it's worth a shot.

xcandyman

10:38 am on Dec 10, 2002 (gmt 0)

10+ Year Member



Thanks for your suggestion lorax but I dont think its what I need. If the host I'm calling is down it will slow the page download time down and not load everything else until that finishes.

What I want is that if the host content is not loaded in a period of time say 5 secs I want to load a local page instead in my iframe saying temp not available.

If I cant do this is there a way to download my dhtml nav menu before the iframe external content?

Thanks

Steve

korkus2000

1:12 pm on Dec 10, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not host it on your site?

xcandyman

1:40 pm on Dec 10, 2002 (gmt 0)

10+ Year Member



I cant. I purchased the external content and they only allow external

lorax

2:10 pm on Dec 10, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



xcandyman,
It'll work. Create a loop that checks time against the onLoad event. Set the timer so the end time is out at some reasonable time limit that would normally account for a slow page load on a 56K modem. While the timer ticks down, use a loop to check for the onLoad event. If the timer reaches the end, initiate your error code. If the onLoad event occurs, kill the timer and initiate your planned code.

xcandyman

2:26 pm on Dec 10, 2002 (gmt 0)

10+ Year Member



What code do I use to do this?

Thanks

Steve

GaryK

3:59 pm on Dec 10, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't see any reference to what web server you're running but with Windows there are plenty of components, including a free one from MS, that will let you set a timeout and then try to load a URL. If it times out you get an error message and an empty string back. If it works the string that's returned is the page or data you requested and you can send the string out as HTML.

xcandyman

4:02 pm on Dec 10, 2002 (gmt 0)

10+ Year Member



Im on a Linux server.

GaryK

4:06 pm on Dec 10, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know Linux very well but I'm sure there must be a similar component or whatever you call it in Linux that can call a remote URL, wait a specified period of time and then return. It's just such a commonly done thing I can't imagine it doesn't exist. Hoefully this thread will bring it to light. HTH.

toadhall

6:37 pm on Dec 10, 2002 (gmt 0)

10+ Year Member



You could muck around with setTimeout() [mozilla.org] and clearTimeOut() [mozilla.org]...

function sorry() {
window.location="path/to/apology.html";
}
var kill = window.setTimeout("sorry()", 10000);

<body onLoad="window.clearTimeout(kill);">

...I've used similar to deal with images that don't load (with onLoad placed in the image tag).

Good luck!

xcandyman

10:10 am on Dec 11, 2002 (gmt 0)

10+ Year Member



How do I put that into my site? where abouts in my page?

Thanks

Steve

toadhall

3:32 pm on Dec 11, 2002 (gmt 0)

10+ Year Member



This was just a suggestion for you to follow up; I haven't tested it at all. Bearing that in mind, the function declaration and the line defining the "kill" variable go in the <head> of the document between javascript "script" tags:

<script language="JavaScript">
<!--
in here
//-->
</script>

... and the other line is of course the <body> tag of your document.

Theory is if the page doesn't load in 10 secs (10000 microseconds) the sorry() function will run and forward the visitor to an "apology" page. If the page does load the timer will be shut off (clearTimeout(kill)) and all's well.

I hope. ;)

xcandyman

5:21 pm on Dec 11, 2002 (gmt 0)

10+ Year Member



Toadhall you are now my new best friend

IT WORKS!

That is a relief. The external host is known to been down sometimes and when it is it kills my site when trying to load it.

YAY!

Thanks