Hey! Do you have any query related to front end?

Sign in Sign up

Detect device by javascriptBack

It is very easy to detect device by JavaScript through "navigator.userAgent" property. This property returns information about the name, version and platform of the browser. Then JavaScript matches the name of browser, it falls in the category of mobile, it simply alerts that user is using mobile otherwise desktop/laptop.


Detect device by javascript


var isMobile = {
	Android: function() {return navigator.userAgent.match(/Android/i);},
	BlackBerry: function() {return navigator.userAgent.match(/BlackBerry/i);},
	iOS: function() {return navigator.userAgent.match(/iPhone|iPad|iPod/i);},
	Opera: function() {return navigator.userAgent.match(/Opera Mini/i);},
	Windows: function() {return navigator.userAgent.match(/IEMobile/i);},
	userAgent : function() {return navigator.userAgent},
	any: function() {return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());}
var displayResult = document.getElementById("displayResult");
	var result = "


"+ isMobile.userAgent()+"

Hey!, You are using Mobile

"; displayResult.innerHTML = result; }else{ var result = "


Hey!, You are using Desktop

"; displayResult.innerHTML = result; }

Although all devices has not been covered but, maximum number of devices has been covered.

how to use

Simply copy and paste the code inside script tag and place it in header tag and, you can place your stuff by replacing alert statement accordingly, if it is for mobile or desktop/laptop.

How to comment:

  • Create an account in discuss by clicking on login next to arrow.
  • Create password for discuss and varify your email id, through your mail.
  • Refresh page and comment.

You might also like

  • Inner page scrolling effect

    Simple jQuery content slider plugin

    • 398
    • 2
    • 398
    • facebook icon
    • twitter icon
    • google plus
  • Centralize your content

    Position your content according to your choice

    • 294
    • 5
    • 294
    • facebook icon
    • twitter icon
    • google plus
  • Side pusher hamburger menu

    Side pusher hamburger menu is a better way put more content on the page.

    • 516
    • 8
    • 516
    • facebook icon
    • twitter icon
    • google plus

Latest quries posted

gopa kumarabout 4 years ago

amit singhabout 4 years ago

rahmat aliabout 4 years ago

mandavi tiwariabout 4 years ago

rahul sharmaabout 4 years ago

Ask question
Latest video
Learn Angular
Profile pic
Guest Back