Jquery to check Mobile Device or Browser

To check whether the page is acceded from mobile device or browser please use below script


//*******************************Jquery For Mobile Device Start ************************************/

$(document).ready(function(){

var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));

if (mobile)
{
alert("MOBILE DEVICE!!");

//Retriev Browser URL
var url = window.location.pathname;

//Get Page Name From browser URL with extenstion
var filename = url.substring(url.lastIndexOf('/')+1);

}
else
{
alert("NOT A MOBILE DEVICE!!");
}

});
//*******************************Jquery For Mobile Device End************************************/

Lie Jquery file URL:

https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s