Prevent iframe "This webpage is not available." error from displaying on website
Asked Answered
J

2

2

Is there a way to prevent the error "This webpage is not available." from displaying within an iframe that displayed on another site?

For example, if I have a website and I want to display my Facebook fans in a box, one way to display it is with an iframe (typically Facebook supplied code). However, if for some reason Facebook is down or slow to respond (like it is right now), I get the following displayed on my website where the iframe should be displayed:

This webpage is not available.

The webpage athttp://www.facebook.com/plugins/likebox.php?id=xxxxxxxxxx&width=182&connections=6&stream=false&header=true&height=287might be temporarily down or it may have moved permanently to a new web address.

• More information on this error Below is the original error message Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.

If Facebook (or the other website) is not available, I'd be happy not displaying anything, or displaying a graphic of the same size (height/width), or a host of other alternatives EXCEPT displaying an error on my homepage! It makes my site look broken to users.

Any and all ideas are welcome! Thanks in advance

Jodijodie answered 23/8, 2010 at 23:1 Comment(0)
E
3

You can use the iframe's onerror="" property to do something creative. Consider this:

<iframe src="foo.bar" onerror="this.location.reload();" />

Hope this helps

Edit: This no longer works.

Emelineemelita answered 23/8, 2010 at 23:7 Comment(4)
onerror for iframe elements is part of the HTML5 specification and, as far as I can tell, is only supported in the latest versions of Chrome and Safari. Firefox, IE and Opera don't support it, although it can't hurt to add this so that it will work when those browsers implement it.Imprison
@Andy: are you sure? i just tested on chromium 9.0.597.94 and onerror doesn't seem to be supportedJoe
@brillout.com: I didn't have the means to properly test it when I wrote that comment. What I did do was type the following command into Chrome's console: "onerror" in document.createElement("iframe"). The result was (and still is for me in 9.0.597.98) true, meaning that Chrome defines a default property/attribute named "onerror" for iframe elements. Its value is null, which is the typical value of initialized event hander properties.Imprison
While the event property does exist in Chrome, it doesn't actually ever get fired, as far as I can tell.Forelli
C
1

If you are doing anything on the server-side you can test that URL and see if it returns a 404 error

Cattish answered 23/8, 2010 at 23:16 Comment(1)
That won't work because you need the clients credentials from their browser to display facebook content .Soulless

© 2022 - 2024 — McMap. All rights reserved.