No-Bullshit Guide to Detecting Everything in HTML5
diveintohtml5.org
diveintohtml5.org
So you get true if the object exists and false otherwise.
!!0 -> false
!!1 -> true
!!"" -> false
!!"s" -> true
!!null -> false
!!undefined -> falseAccording to the spec, media.canPlayType returns either "", "maybe" or "probably". An empty string "" is falsy in Javascript and a non-empty string is truthy, but if you try and compare them directly with booleans then you can get some odd behaviour:
if ("yes"){ // true }
if ("yes" == true){ // false }
if ("yes" === true){ // false }
if (""){ // false }
if ("" == false){ // true }
if ("" === false){ // false }
I personally prefer to make sure that any function which you're expecting the return value to be used as a boolean actually returns a boolean value. I know there are many people out there with a dislike of !! though.Try putting things like these into the address bar of your browser:
javascript:alert(!!null)
javascript:alert(!!undefined)
javascript:alert(!!{})
javascript:alert(!!Math.floor)Curiously, under Konqueror 4.3 I can highlight those words, together with the rest of the title, but pasting (either X or ^c^v) also misses them ...
The second issue is CSS generated content. I honestly don't remember why I chose to put chapter numbers and appendix letters in CSS and the rest of the title in content. Purity? Really? That doesn't sound like me. ;-) It would probably be simpler to move it all into the h1.
function checkForTransitionSupport() { var cssTransitionsSupported = false; var div = document.createElement('div'); div.innerHTML = '<div style="-webkit-transition:color 1s linear;-o-transition:color 1s linear;-moz-transition:color 1s linear;"></div>'; cssTransitionsSupported = (div.firstChild.style.webkitTransition !== undefined) || (div.firstChild.style.OTransition !== undefined) || (div.firstChild.style.MozTransition !== undefined); delete div; return cssTransitionsSupported; }
- The <audio> and <video> elements
- The <canvas> element
- Form validation (without JavaScript!)
- New <input>s for data like dates, times, numbers, ranges, and colors, for which the UA can provide OS-native controls
- An API for cross-domain communication between windows
- An API for providing and accepting drag and drop within, between, into, and out of browser windows
- Web Workers for computation in the background
- Web Sockets for efficient communication with your server
- A persistent local database
...and much more!
This page focuses on detecting support for many HTML5 features in JavaScript, so that a developer could, say, swap in their own datepicker if the browser doesn't offer one.
http://github.com/Modernizr/Modernizr
My longer chapter on detecting HTML5 features ( http://diveintohtml5.org/detect.html ) explains the detection patterns, and shows how to detect things with or without Modernizr. I've been working with the Modernizr developers to expand their detections, and at the same time some of the code in this guide is taken directly from Modernizr.
*within reason obviously...