Saturday, November 12, 2011

How to detect iPad, Iphone using jQuery/javascript

Use below simple snippet of code to detect iPad.
<script type="text/javascript">
function chkiPad(){
return (navigator.platform.indexOf("iPad") != -1);
}
</script>
jQuery code for iphone / ipad / ipod detect:
<script type="text/javascript">
$(document).ready(function(){
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
if (agentID) {
// write your code
}
});
</script>

No comments: