This solution by Kevin Martin is tested and seems to be giving the correct result in IE, FF and Chrome:
function iframeDataURITest(src) {
var support,
iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.setAttribute('src', src);
document.body.appendChild(iframe);
try {
support = !!iframe.contentDocument;
} catch (e) {
support = false;
}
document.body.removeChild(iframe);
return support;
}
console.log('Empty data uri', iframeDataURITest('data:;base64,'));
console.log('"*" data uri', iframeDataURITest('data:text/html;base64,Kg=='));
Unlike some of the other suggestions, it is synchronous - no need to mess around with timeouts or callbacks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…