Skip to content

Instantly share code, notes, and snippets.

@sudo-ben
sudo-ben / detectDataURL.js
Last active June 16, 2016 07:28 — forked from bgrins/detectDataURL.js
Detect if a string is a data URL. Doesn't try to parse it or determine validity, just a quick check if a string appears to be a data URL. See http://jsfiddle.net/bgrins/aZWTB/ for a demo.
function isDataURL(s) {
var commaIndex = s.indexOf(',');
if (commaIndex === -1) {
return false;
} else {
try {
window.atob(s.slice(commaIndex + 1));
return true;