Skip to content

Instantly share code, notes, and snippets.

@tzi
Created June 19, 2012 08:44
Show Gist options
  • Save tzi/2953065 to your computer and use it in GitHub Desktop.
Save tzi/2953065 to your computer and use it in GitHub Desktop.
How to detect the Data-Uri support in javascript
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to detect the Data-Uri support in javascript</title>
<link href="no-data-uri.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<script type="text/javascript" src="no-data-uri.js"></script>
<body>
</html>
body {
background-color: green;
}
body.no-data-uri {
background-color: red;
}
(function(){
var datauri = new Image();
datauri.onerror = function() {
document.body.className += ' no-data-uri';
};
datauri.onload = function() {
if (datauri.width != 1 || datauri.height != 1) {
document.body.className += ' no-data-uri';
}
};
datauri.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment