Using JavaScript you can check for the touchstart
event in document.documentElement
to detect touch devices:
var isTouch = 'touchstart' in document.documentElement;
Then on Android you can check the userAgent to see if it's a mobile phone:
var isMobile = navigator.userAgent.toLowerCase().indexOf("mobile") > -1;
On IOS simply check for iPhone
:
var isMobile = navigator.userAgent.toLowerCase().indexOf("iphone") > -1;
The rest of the party you can add on yourself. Hope you get the picture:
var isTouch = 'touchstart' in document.documentElement,
ua = navigator.userAgent.toLowerCase(),
isMobile = isTouch ? ua.indexOf("android") > -1 ? ua.indexOf("mobile") > -1 : ua.indexOf("iphone") > -1 : false;
A little complex.
Just to quick answer your comment:
onload = function() {
var isTouch = 'touchstart' in document.documentElement,
ua = navigator.userAgent.toLowerCase(),
isMobile = isTouch ? ua.indexOf("android") > -1 ? ua.indexOf("mobile") > -1 : ua.indexOf("iphone") > -1 : false;
if ( isMobile ) {
document.getElementById("mobileLink").style.display = 'block';
document.getElementById("browserLink").style.display = 'none';
}
else {
document.getElementById("mobileLink").style.display = 'none';
document.getElementById("browserLink").style.display = 'block';
}
}
And your HTML:
<div id="mobileLink">Feel free to give me a <a href="tel:1-408-555-5555">call</a</div>
<div id="browserLink">Feel free to give me a <a class='lightview' data-lightview-type="iframe" href="pages/call.html" data-lightview-options="width: 230, height: 101">call</a>.</div>