Last active
March 9, 2017 22:08
-
-
Save arozwalak/7468966 to your computer and use it in GitHub Desktop.
Javascript: Feature detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Feature Detection</title> | |
</head> | |
<body> | |
<input type="text" placeholder="John Doe"> | |
<input type="email"> | |
<script> | |
if (!'placeholder' in document.createElement('input')) { | |
// a polyfill | |
} | |
function testSupport (type) { | |
var i = document.createElement('input'); | |
i.setAttribute('type', type); | |
return i.type === type; | |
} | |
if ( !testSupport('email')) { | |
// provide fallback | |
} | |
if (document.createElement('canvas').getContext) { | |
// browser supports canvas | |
} | |
if (document.createElement('audio').canPlayType) { | |
// browser supports audio | |
} | |
if (document.createElement('video').canPlayType) { | |
// browser supports video | |
} | |
function supportsStorage() { | |
try { | |
return 'localStorage' in window && window.localStorage !== null; | |
} catch(e) { | |
return false; | |
} | |
} | |
if (!!navigator.geolocation) alert('track me!'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment