note that there's few typos in this page ("testWepP", "===", missing "callback" parameter...) .
Also: one may want to test 0.2.0 explicitly, using a lossless image.src base64 data.
Here's a corrected example HTML script:
<!DOCTYPE html>
<title>WebP 0.2.0 detection</title>
<script>
function testWebP(callback) {
var webP = new Image();
webP.src = "data:image/webp;base64,UklGRi4AAABXRUJQVlA4TCEAAAAvAUAAEB8wAiMw"
+ "AgSSNtse/cXjxyCCmrYNWPwmHRH9jwMA";
webP.onload = webP.onerror = function () { callback(webP.height == 2); };
}
window.onload = function() {
testWebP(function(supported) {
alert("WebP 0.2.0 " + (supported ? "supported!"
: "not supported.")); }
);
}
</script>
<body>detecting...</body>
</html>
This script tests for 0.2.0.
For testing the 'old' 0.1.0 -> 0.1.3 versions (only lossy), one could use instead:
webP.src = "data:image/webp;base64,UklGRjAAAABXRUJQVlA4ICQAAACyAgCdASoCAAIAL/3+/3+pqampqYH8SygABc6zbAAA/m1AAAA="