将data URIs用于图片的可靠方法是什么?我知道IE6 / 7不支持它们,所以这有用吗?
<noscript>
中包含图片(而不是数据)。我的问题是:即使浏览器支持javascript和数据URI,是否会在<noscript>
中提取图像?
答案 0 :(得分:0)
如果你确实想走这条路(我个人不打扰),你可以这样做......
// 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;
}
}