Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Same Markup: Using , , and


03 Sep 2010   #1

 
Same Markup: Using , , and

Quote:
On this blog we’ve repeatedly discussed enabling the "Same Markup" for Internet Explorer 9. Part of making "Same Markup" a reality involves supporting the right features in IE9 to make the same HTML, JavaScript, and CSS "just work" the same way they do in other browsers. Part of how IE9 contributes to enabling the "Same Markup" is through support for the , , and elements from HTML5. These were introduced in the third platform preview and continue to be improved with each update.

In my first post on "Same Markup", I described the effort as an "n-way street". Each browser has a part to play by supporting the right features with the right behavior. Web developers also have a part to play in how they code for cross-browser differences where they unfortunately still exist. The most important part of working across browsers for web developers is to detect features, not browsers. So in this post I'll outline how to use feature detection for , , and .

Detecting Support from HTML Markup

Unlike other features, support for , , and can be detected directly from HTML markup. This involves simply using the desired element, then placing fallback content inside of it intended for browsers that don't have support for these elements. Browsers with support will hide this content from the user and display only the , , or element itself.

This text only displays in browsers without canvas support. This text only displays in browsers without audio support. This text only displays in browsers without video support.
One caveat to keep in mind is that fallback content is only hidden visually. Of course, fallback content should also be useful. Exactly what qualifies as useful can vary depending on what you are trying to do. One approach is to point the user at a download for an upgrade, but in most cases it is a better experience for consumers to fall back to alternative approaches for delivering the content. For example, if you're drawing something that doesn't change much to a canvas, you may be able to fall back to an image that gets generated server-side. A better alternative could involve including a framework which implements canvas on top of existing web technologies or using a widely deployed plug-in.

The and elements tend to have more options for fallback via plug-ins, whether through a media player or an app built on top of a widely deployed technology such as Flash or Silverlight. At the very least you can provide the user with a link to download the file so they can play it locally. The examples below provide a rough view of this type of fallback, though the tag generally requires a number of varying parameters specific to the chosen plug-in.

Download the audio file Download the video file Detecting Support from Script

In addition to HTML markup, support for , , and can also be detected from script. This detection can be performed many ways, but one of the simplest is to check for the existence of the appropriate interface object off of window.

// Example 7: Simple feature detection for if(window.HTMLCanvasElement) { // Code requiring canvas support}// Example 8: Simple feature detection for if(window.HTMLAudioElement) { // Code requiring audio support}// Example 9: Simple feature detection for if(window.HTMLVideoElement) { // Code requiring video support}An alternative approach for detecting and involves checking for the existence of the canPlayType method on a dynamically created or element. This is used by a number of frameworks and is generally preferred if you also intend to use the canPlayType method to test for supported codecs (which will be covered in a future post). If you simply need to test whether or is supported, then I find the approach outlined above in examples 8 and 9 to be more obvious and equally as effective.

// Example 10: Alternate feature detection for if(document.createElement("audio").canPlayType) { // Code requiring audio support}// Example 11: Alternate feature detection for if(document.createElement("video").canPlayType) { // Code requiring video support}A similar alternative approach can be used for detecting support. In this case, most frameworks have settled on checking for the existence of the getContext method. This makes sense for given that this method is required in order to retrieve a context for rendering.

// Example 12: Alternate feature detection for if(document.createElement("canvas").getContext) { // Code requiring canvas support}Next Steps

If you have previously used browser detection to decide whether to use , , or , now is the time to update to use feature detection instead. Also, make sure you have a DOCTYPE at the top of your page (e.g. ) so your content doesn't render in Quirks Mode. In IE9, Quirks Mode is used for compatibility and consequently the , , and elements will not work there.

Stay tuned for future posts covering how to detect supported codecs and specify multiple sources using the and elements.

Tony Ross
Program Manager


More...

My System SpecsSystem Spec
.

04 Sep 2010   #2

Windows 7 Home Premium 64 bit
 
 

Thanks for the post Sarge. Good to see you again. Been a while
My System SpecsSystem Spec
Reply

 Same Markup: Using , , and




Thread Tools




Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 05:04 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33