I want to perform a check in one of my JavaScript functions that determines whether I am on a smartphone and then decide whether or not to run the function based on the results.
What is the best way to detect/check for a smartphone (or handheld device in general) in JavaScript?
e.g.
if (user is on a smartphone) {
//run this code if on a phone
} else {
//run this code if not on a phone
}
If there is not one definite method to check for a phone, then what are the best selection of checks I should to perform before deciding which code to run?
EDIT/UPDATE: The answers and comments on this similar post should give me something to go on - What is the best way to detect a mobile device in jQuery?