Content deleted Content added
m Dating maintenance tags: {{Citation needed}} |
|||
Line 1:
:''This article is about the web development technique. For the neurological process, see [[feature detection]], or for the computer vision technique, see [[feature detection (computer vision)]].''
'''Feature detection''' (also '''feature testing''') is a technique used in [[web development]] for handling differences between [[runtime environments]] (typically [[web browsers]] or [[user agents]]), by programmatically testing for clues that the environment may or may not offer certain functionality. This information is then used to make the application adapt in some way to suit the environment: to make use of certain [[API|APIs]], or tailor for a better user experience.{{Citation needed|date=March 2014}}
Its proponents claim it is more reliable and future-proof than other techniques like [[User_agent#User_agent_sniffing|user agent sniffing]] and browser-specific CSS hacks.{{Citation needed|date=March 2014}}
==Techniques==
A feature test can take many forms. It is essentially ''any'' snippet of code which gives some level of confidence that a required feature is indeed supported. However, in constrast to other techniques, feature detection usually focusses on performing actions which directly relate to the feature to be detected, rather than [[heuristics]].{{Citation needed|date=March 2014}}
As [[JavaScript]] is the most prevelent [[scripting language]] in web browsers{{Citation needed|date=March 2014}}, many feature detection techniques use JavaScript to inspect the [[Document Object Model|DOM]] and local JavaScript environment.
The simplest technique is to check for the existence of a relevant object or property. For example, the Geolocation API (used for accessing the device’s knowledge of its geographical ___location, possibly obtained from a [[GPS navigation device]]) exposes a <code>geolocation</code> property on the <code>navigator</code> object in the DOM; the presence of which implies the Geolocation API is supported:
|