Detecting mobile devices:
Simple browser sniffing
if (/mobile/i.test(navigator.userAgent)) {...}
jQuery.browser.mobile plug-in (exhaustive browser sniffing)
Simple test for touch events
if ('ontouchstart' in window) {...}
Advanced test for touch events:
if (('ontouchstart' in window) || // Advanced test for touch events
(window.DocumentTouch && document instanceof DocumentTouch) ||
((hash['touch'] && hash['touch'].offsetTop) === 9)) {...}
Optionally use onorientationchange
for #3 and #4 above.
Combine 1 or more of these (and any other approaches) as needed. None of them are foolproof.
onorientationchange
can be a property ofwindow
if that's available. My browser doesn't have it, but it seems like a valid event - #5285378 – Flied