Skip to content

Instantly share code, notes, and snippets.

@Takazudo
Created October 12, 2010 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Takazudo/621906 to your computer and use it in GitHub Desktop.
Save Takazudo/621906 to your computer and use it in GitHub Desktop.
iPhone, iPad UA detection
/* $.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