Sometimes we need to know where the user came from, for example, if this is desktop then show button, or if this is a smart phone display this larger button.

Well, I have not found another way to do this without using javascript. So, here’s the code.


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 are using a mobile phone to view this page..');
	alert('You are using a desktop browser to view this page..');

The code takes the useragent (a string that contains information about the browser) and compares with a list of mobile devices. If the useragent contains any of the mobile phones in the list of declared returns true, then you know it is a mobile phone or a desktop. Thus, you can redirect eg, the mobile user to a different page.


Ajax and Browser History – Detect mobile device / phone with javascript

David Walsh Blog – iPad Detection Using JavaScript or PHP

Also View

javascript – ReplaceAt

jQuery – Disable HTML Controls

jQuery – Dialog

jQuery – .ready

jwplayer – Show First Frame

jQuery – Themes List at Google Code


Não se esqueça de deixar seu comentário, critica, elogio, dúvida e etc. Ele é muito importante para a melhoria do blog.
Do not forget to leave your comments, criticism, praise, questions, etc.. It is very important for improving the blog.


Comments on: "javascript – Detect Mobile" (4)

  1. […] javascript – Detect Mobile […]

  2. […] javascript – Detect Mobile […]

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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

%d bloggers like this: