Wednesday, 20 March 2013

Javascript to detect mobile browser

Javascript to detect mobile browser....

put this javascript on page and it will detect that the device is mobile,tablet and ipad or not.

<script type="text/javascript">

var mobile = function(){
return {
var uagent = navigator.userAgent.toLowerCase();
var list = this.mobiles;
var ismobile = false;
for(var d=0;d<list.length;d+=1){
ismobile = true;
return ismobile;
"windows ce","benq","mda","mot-","opera mini",
"philips","pocket pc","sagem","samsung","sda",

  alert(you have opened page in mobile, tablet or ipad.);
                   //following line is to open mobile version of page.
window.location = ""
                    alert('You are using a desktop browser to view this page..');