Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirect to another page if page cannot be displayed in iframe

Status
Not open for further replies.

moron3

Technical User
Dec 2, 2008
17
US
Is it possible to write a script that will redirect to a different page(or go back to the same page) if the intended forwarded to page cannot be displayed, such as if the server is down or the page is not there anymore?

The script will be in a page that will be displayed in an iframe.

 
If the target url that the iframe is directed to is unavailable, i'd like to point it to a different page.

I think you could give the page time to load(and in this case I could wait 10 seconds or more because the iframe is far down on a very long page) then check the locationName of that iframe, and if it's blank, then the page couldn't be displayed so that's when you direct the iframe to a different url.

But I wouldn't know how to write that.
 
Here's some steps that might work for you:

1) Attach an onload event to the empty iframe
2) Start a timer (say, 10 seconds)
3) Set the iframe's URL

Then:

- If the timer fires before the onload event, you know the page has timed out

- If the onload event fires before the timer, the page has loaded.

Note: This does NOT necessarily tell you if the target page is unavailable or not, as it might be available but taking a long time to load.

You could also use an AJAX request to perform a similar task.

Hope this helps,
Dan


Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
BillyRay,

I tried what you said but if the page cannot be displayed such as if the page is not found it triggers the onload event immediately.

But if I could check the locationName at the onload event and it was blank, I'd know the page hadn't loaded.

Do you know how to check the locationName of a url inside an iframe?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top