Detecting Mobile Devices with JavaScript

You have website and also mobile site want to detect device at startup and redirect to user to the right page! here is the solution…..

<html>
<head>
<script type=”text/javascript”>
var mobile = function(){
return {
detect:function(){
var uagent = navigator.userAgent.toLowerCase();
var list = this.mobiles;
var ismobile = false;
for(var d=0;d<list.length;d+=1){
if(uagent.indexOf(list[d])!=-1){
ismobile = true;
}
}
return ismobile;
},
mobiles:[
“midp”,”240×320″,”blackberry”,”netfront”,”nokia”,”panasonic”,
“portalmmm”,”sharp”,”sie-“,”sonyericsson”,”symbian”,
“windows ce”,”benq”,”mda”,”mot-“,”opera mini”,
“philips”,”pocket pc”,”sagem”,”samsung”,”sda”,
“sgh-“,”vodafone”,”xda”,”palm”,”iphone”,
“ipod”,”ipad”,”android”,”windowsphone”
]
};
}();

if(mobile.detect()){
//alert(‘You are using a mobile phone to view this page..’);
window.location = “http://www.soykansoft.com/codiQa/app.html&#8221;;
}else{
//alert(‘You are using a desktop browser to view this page..’);
window.location = “http://www.soykansoft.com/&#8221;;
}
</script>
</head>

<body>
</body>

</html>

Advertisements