后备图像和超时 - 外部内容。使用Javascript [英] Fallback image and timeout - External Content. Javascript
本文介绍了后备图像和超时 - 外部内容。使用Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果外部图像未加载或加载时间过长,设置本地回退图像的最佳方法是什么。
What is the best way to set up a local fallback image if the external image does not load or takes too long to load.
推荐答案
你可以添加一个oneror处理程序:
You can add an oneror handler:
<img src="http://example.com/somejpg.jpg"
onerror='this.onerror = null; this.src="./oops.gif"' />
注意在处理程序中将onerror设置为null,这样如果oops.gif可以浏览器不会死因某种原因不能加载。
Note setting onerror to null in the handler so that the browser doesn't die if oops.gif can't be loaded for some reason.
这篇关于后备图像和超时 - 外部内容。使用Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文