var device = { detect: function(key) { if(this['_'+key] === undefined) { this['_'+key] = navigator.userAgent.match(new RegExp(key, 'i')); } return this['_'+key]; }, iDevice: function() { return this.detect('iPhone') || this.detect('iPod'); }, android: function() { return this.detect('Android'); }, webOS: function() { return this.detect('webOS'); }, mobile: function() { return this.iDevice() || this.android() || this.webOS(); } }; I've used something like this in the past. This is similar to a previous response, but it's technically more performant in that it caches the result of the match, especially if the detection is being used in an animation, scroll event, or the like.