has.js
has.js tests are very simple to perform and use has('feature')
like syntax and return a Boolean value. The code in the previous example could be written as:
<script> var videoElement = ""; $(document).ready(function(){ if(has("video")){ // video is supported by the browser and can play it. $("#result").html("Video is supported"); videoElement = document.createElement('video'); $("body").append(videoElement); }else{ // load via flash or something else $("#result").html("Video is not supported, use Flash or something else."); } }); </script>
In this case, has("video")
will return a Boolean value to help developer make a decision. Sometimes features are partially supported. To understand this, let's take the same example of displaying video ...
Get Test-Driven JavaScript Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.