December 2015
Intermediate to advanced
240 pages
4h 57m
English
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 ...