Reputation: 3587
I am detecting what kind of mobile browser a user has and would like to show the appropriate download link to the right App based on that. So Android to the Android App, Iphone to the Iphone App, etc.
so this simply puts out a True or False if you are using an iPhone or not:
<script type="text/javascript">
<!--
document.write(DetectTierIphone());
// -->
</script>
I just need a nice simple Javascript if statement showing the iphone DIV if a the code above if TRUE.
<div class="iphone">
<a>link</a>
</div>
<div class="android">
<a>link</a>
</div>
<div class="blackberry">
<a>link</a>
</div>
Any help getting this started?
Thanks
Upvotes: 2
Views: 2428
Reputation: 9825
Try something like this:
<script>
$('div.iphone, div.android, div.blackberry').hide();
if( navigator.userAgent.match(/Android/i)){
$('div.android').show();
} else if ( navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPod/i)){
$('div.iphone').show();
)
</script>
I hope this helps!
Upvotes: 0
Reputation: 41080
if ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1)) {
alert('iOS');
}
Upvotes: 1
Reputation: 4615
You need hide all divs initially, then use the .show() method:
var ua = navigator.userAgent;
if (/iPhone|iPad|iPod/i.test(ua))
$('div.iphone').show();
else if (/Android/i.test(ua))
$('div.android').show();
else if (/Blackberry|RIM\sTablet/i.test(ua))
$('div.blackberry').show();
Upvotes: 2