HTML5 Feature Support Detection

HTML5 is a collect of individual features, that currently are either supported or not by the current array of browsers. The best approach I’ve found at this time, is to write for HTML5 and use other tools to downgrade graceful.

The following are some detection techniques that are in use today:

Input Types: HTML5 defines over a dozen new input types for use in web forms. For determining which of these new form elements is supported use the following code, per element (yes I know, that’s a pain in the ass, but you gotta do what you gotta do)

var input = document.createElement("input");
input.setAttribute("type", "color");
return i.type !== "text";

Aha, but if you don’t want to write these input checks, Modernizr has a hash it builds to detect all of the new input types.

if (!Modernizr.inputtypes.date) {
	// ?? <- See example of this.
}

Video Formats: Video formats, or codecs, is the algorithm which is used to encode video. Checking if a video element object has the canPlayType for a particular codec will determine support.

function supports_video() {
    return !!document.createElement('video').canPlayType;
}

Again Modernizr can make this detection much simpler.

if (Modernizr.video) {
	if (Modernizr.video.ogg) {

	} else if (Modernizr.video.h264) {
		// H.264
	}
}

Canvas: The canvas element is a resolution independent bitmap canvas which can be used for rendering graphs, game graphics, or other visual images on the fly. To check for canvas attempt to create a canvas element on the document object and retrieve the context. Context dictates if there is or is not context support.

function supports_canvas() {
	return !!document.createElement('canvas').getContext;
}

Of course, there is a Modernizr Function to determine support too.

if (Modernizr.canvastext) {
	// let's draw some text!
} else {
	// no native canvas text support available
}

Geolocation: Geolocation is the function of determining where you are by using the UP address, wireless network connection, cell tower, GPS software, or other device. The Geolocation Working Group is actually working on this feature, not particularly the HTML5 Working Group, but the feature is closely correlated to the entire HTM5 spec and is currently being integrated into most browsers.

The code snippet below can be used to determine if geolocation is available.

function supports_geolocation() {
	return !!navigator.geolocation;
}

If you don’t want to write this particular function, you could also use the Modernizer Library.

if (Modernizr.geolocation) {
	// process the location...
} else {
	// no native geolocation support, so start hacking!
}
4 comments
  1. Pingback: DotNetShoutout

    • Adron said:

      I’ll have to check it out. Thx for the reference.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

midnight mystery ride

at midnight, we ride.

Riding on Roadways

Writing on Riding on Roadways

Not Rich Yet

It's going to happen. Gotta find something to do until then.

Portland Transit Lane - The Untold Stories of Transit In Portland

“So over you is the greatest enemy a man can have and that is fear. I know some of you are afraid to listen to the truth—you have been raised on fear and lies. But I am going to preach to you the truth until you are free of that fear…” — Malcolm X

craftedincarhartt

Carhartt Women's Blog

heydev

For the love of code

Nathan Evans' Nemesis of the Moment

My nemesis of the moment

Open Source Bridge: Presentation Proposals

Snippets, software architecture, lean, agile, management, and leadership bits.

Captured Refractions

A collection of my latest adventures, past reflections and other photos.

for the love of Nike

for the love of Nike

The Cloud Dev

Developing {for/ on/ the} Cloud...

Project Manager in a Cloudy IT World

Thoughts, comments and ideas from experiences as a Project Manager in IT

iBikeuBike

If I can bike... So can you!

MAX FAQs

Portland Light Rail

UX Success

User Experience Design, Agile Development, Lean UX, Start Up

The lost outpost

a weblog by Andy Piper about technology, photography, and life

SaintGimp

Agile development, software craftsmanship, continuous improvement - Eric Lee's blog

Clang and Clamour

pardon the construction noises while we build the internet

Kristen Mozian

social {good} design + experience

RightScale Blog

Cloud Management News & Conversations

Follow

Get every new post delivered to your Inbox.

Join 5,492 other followers

%d bloggers like this: