题
什么是可靠的使用方式 数据URI 对于图像?我知道IE6/7不支持它们,所以这会起作用吗?
- 我默认使用数据uris进行图像
- 如果浏览器是IE6/7,则使用JavaScript显示图像(不是数据,而是实际图像)
- 在
<noscript>
.
我的问题是:图像会在 <noscript>
即使浏览器支持JavaScript和Data URI?
解决方案
如果您想走这条路(我个人不会打扰),您 可以 做...
// Parse user agent and figure out if this browser supports data
// URIs - e.g. `supportDataUri()`. Also, store the image path
// somewhere - I'll assume for convenience an attribute called `data-image-src`
if ( ! supportDataUri()) {
var images = document.getElementsByTagName('img');
for (var i = 0, imagesLength = images.length; i < imagesLength; i++) {
var imgSrc = images[i].getAttribute('data-image-src');
images[i].src = imgSrc;
}
}
不隶属于 StackOverflow