HTML and CSS Reference
In-Depth Information
10
Feature Detection
A spiring JavaScript developers developing for the general web are faced with a
rather unique challenge, in that very little is known about the environments in which
scripts will execute. Even though we can use web analytics to gather information
about our visitors, and external resources such as Yahoo's graded browser support
to guide us in decisions relevant to cross-browser development, we cannot fully
trust these numbers; neither can they help make our scripts future proof.
Writing cross-browser JavaScript is challenging, and the number of available
browsers is increasing. Old browsers see new version releases, the occasional new
browser appears (the most recent noticeable one being Google Chrome), and new
platforms are increasingly becoming a factor. The general web is a minefield, and
our task is to avoid the mines. Surely we cannot guarantee that our scripts will
run effortlessly on any unknown environment lurking around the Internet, but we
should be doing our very best to avoid ruining our visitors' experience based on
bad assumptions.
In this chapter we will dive into the technique known as feature detection,
arguably the strongest approach to writing robust cross-browser scripts. We will
see how and why browser detection fails, how feature detection can be used in its
place, and how to use feature detection to allow scripts to adjust in response to
collecting knowledge about the environment's capabilities.
197
 
 
Search WWH ::




Custom Search