Prevent iframe “This webpage is not available.” error from displaying on website

我们两清 提交于 2019-12-04 04:52:13

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3552355/prevent-iframe-this-webpage-is-not-available-error-from-displaying-on-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!