Skip to content

Instantly share code, notes, and snippets.

View david-mark's full-sized avatar

David Mark david-mark

  • David Mark LLC
  • West Chester, OH
View GitHub Profile
@david-mark
david-mark / devicetype.md
Last active January 5, 2017 13:31
How to Detect the Device Type?

#How to Detect the Device Type?

The question of how to detect the device type running the given browser comes up a lot these days. It's virtually the same question as how to detect the browser (or browser version). It's often incorrectly "solved" in the same way, using indirect inferences based on browser sniffing.

##What is the Problem?

As with most such problems in browser scripting, it's best to look at what is to be inferred from such information. We know from experience that such information will often be based on coincidence and will expire at some point in the future, so it is best not to rely on it. An issue at the turn of the century was how to determine whether the browser was IE or not. But why was that information thought to be necessary? For example, at the time IE used attachEvent instead of the standard addEventListener to add event listeners.

##Indirect Inferences