Created
October 12, 2010 09:17
-
-
Save Takazudo/621906 to your computer and use it in GitHub Desktop.
iPhone, iPad UA detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* $.ua: iPhone, iPad, iPod detection */ | |
/** | |
* $.ua | |
*/ | |
$.ua = (function(){ | |
var o = {}; | |
var ua = navigator.userAgent; | |
$.each(['iPhone', 'iPod', 'iPad'], function(i, current){ | |
o[current] = Boolean(ua.match(new RegExp(current, 'i'))); | |
o.appleDevice = o.appleDevice || o[current]; | |
}); | |
return o; | |
})(); | |
/** | |
* test | |
*/ | |
$(function(){ | |
/* | |
<ul id="test"></ul> | |
prepare this element and do... | |
*/ | |
$('#test').append( | |
'<li>iPhone? ' + $.ua.iPhone + '</li>', | |
'<li>iPod? ' + $.ua.iPod + '</li>', | |
'<li>iPad? ' + $.ua.iPad + '</li>', | |
'<li>appleDevice? ' + $.ua.appleDevice + '</li>' | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment