I am using the below code to detect for mobile and I want to detect either Android only or iOS only. I tested the mobile detect with if( isMobile.iOS() ) alert('iOS');
and it shows the alert.
But I want to display the Android Google Play badge if it is Android and the Apple store badge if it is iOS but for some reason the below code isn't working. Can someone tell me what I am doing wrong?
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad /i);
},
};
if (isMobile.Android()) {
document.getElementById("googlePlayBadge").innerHTML = "<img src='modal-img/googlePlayBadge.png' alt='Google Play' class='img-responsive' />";
} else {
if (isMobile.iOS())
document.getElementById("appStoreBadge").innerHTML = "<img src='modal-img/appStoreBadge.png' alt='App Store' class='img-responsive' />";
};
<section class="text-center">
<div id="appStoreBadge"></div>
<div id="googlePlayBadge"></div>
</section>