DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Languages
  4. Tutorial: Get Your HTML5 Working Everywhere: Browser and Feature Detection

Tutorial: Get Your HTML5 Working Everywhere: Browser and Feature Detection

John Esposito user avatar by
John Esposito
·
Nov. 02, 11 · Interview
Like (0)
Save
Tweet
Share
5.20K Views

Join the DZone community and get the full member experience.

Join For Free

During the ancient dyadic browser wars, when IE and Netscape were the USA and USSR of the web (but which was which?), and IE grew (for a while) closer and closer to Windows, web developers could ask just one question: which browser is rendering my pages?

Now, as the browser theater has expanded, and the rendering machines are multiform, and the differences among the browers are no longer so clear-cut -- the web developer's old browser worry has mutated into a problem potentially much bigger and more complex.

But there's another way: worry about the features, not the browser.

The reason is simple. Since no browser today is seeking dominance quite like fifteen years ago, all the browsers are more or less trying to conform to, if also shape, the new, universal HTML5 standard.

Of course, not all browsers quite agree on what HTML5 is. But they differ only in the details -- not in their basic happiness with HTML5 (whatever that may be/come).

In this spirit, Sascha Corti has written a great little tutorial on browser and feature detection. You'll learn how to detect browsers in JavaScript, if you like (more useful for the really antiquated browsers), or specific features, which (for any non-geezer browser) might be a better idea.

For example, here's how easy it is to detect whether HTML5 Canvas is supported:

<script type="text/javascript">
  functionisCanvasSupported()
  {
    var elem = document.createElement('canvas');
    return!!(elem.getContext && elem.getContext('2d');
  }
</script>

The function just returns true or false.

Or, if you'd rather write directly for elegant degradation, here's how to use the HTML5 <video> element with a Silverlight fallback:

<video>
    <source src="video.mp4" type='video/mp4' />
    <source src="video.webm" type='video/webm' />
    <object type="application/x-silverlight-2">
        <param name="source" value="http://url/player.xap">
        <param name="initParams" value="m=http://url/video.mp4">
    </object>
    Download the video <a href="video.mp4">here</a>.
</video>

Sascha's article is full of great snippets and explanations like this. He even walks you through every step of debugging and testing (something tutorials often leave up to the reader), using in-browser developer tools.

If you want to ride the HTML5 wave but are careful enough to look for the sandbars that will hold you back, check out the article and maybe save some of the snippets for later use and re-use.

HTML

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • When Should We Move to Microservices?
  • Documentation 101: How to Properly Document Your Cloud Infrastructure Project
  • Demystifying the Infrastructure as Code Landscape
  • OpenVPN With Radius and Multi-Factor Authentication

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: