JavaScript Navigator property is a build in JS object having information of User Agent, which includes browser name, OS, OS Version, device etc. navigator.useragent can give information regarding Operating System, OS Version, device, browser name and version etc.


    window.navigator;

JS navigator Properties and methods


userAgent

navigator.userAgent property returns information of user's device, including HTML Version, Operation System, OS Version, Browser name, browser version, browser layout engine etc. See example


    navigator.userAgent;

Check Browser using userAgent

How to check web browser using JavaScript using navigator.userAgent.


    if(navigator.userAgent.search("Edge")!=-1){
        console.log("Edge");
    }
    else if( navigator.userAgent.search("Chrome")!=-1){
        console.log("Chrome");
    }
    else if(navigator.userAgent.search("Firefox")!=-1){
        console.log("Firefox");
    }
    else if(navigator.userAgent.search("Safari")!=-1){
        console.log("Safari");
    }
    else if(/MSIE|Trident|Edge\//.test(navigator.userAgent)){
        console.log("Internet Explorer");
    }
    else{
        console.log("Unknown Browser");
    }
        

appName

navigator.appName property returns the name of browser. All HTML5 based browsers returns Netscape. See example


    navigator.appName

appVersion

navigator.appVersion property returns version of web browser. In HTML5 based browsers, the first value in string, i.e 5.0 is version of HTML and then followed by OS information. See example


    navigator.appVersion;

platform

navigator.platform property returns the platform of browser. For Mac OS, it is "MacIntel". See example


    navigator.platform

language

navigator.language property returns language of web browser. See example


    navigator.language;

onLine

navigator.onLine property returns boolean value true if system is connected to network. If not connected, false will be returned.


    navigator.onLine;

Device Memory

navigator.deviceMemory property returns the device memory or RAM in gbs .


    navigator.deviceMemory;

vibrate

navigator.vibrate method can vibrate your smartphone with n no of milliseconds. n parameter in vibrate method is no of milliseconds. See example




    navigator.vibrate(100);    // vibrate for 0.1 sec
    navigator.vibrate(500);    // vibrate for 0.5 sec
    navigator.vibrate(1000);    // vibrate for 1 sec
    navigator.vibrate(2000);    // vibrate for 2 sec

getBattery

getBattery is obsolete feature used to get battery related information from system. This feature is no longer supported.


if(navigator.getBattery){
navigator.getBattery().then(function(x){ console.log(x.level)});
navigator.getBattery().then(function(x){ console.log(x.dischargingTime)});
}
else{
console.log("Battery Api Not Supported")
}

Battery Indicator

This is the battery level indicator of your system based on battery api and HTML5 Meter Element.


geoLocation

navigator.getLocation method is used to get geolocation information of user. This article is already published in HTML5. Click below for Geolocation API


    navigator.geolocation.getCurrentPosition(function(e){
        console.log(e.coords.latitude);
        console.log(e.coords.longitude);
        console.log(e.coords.accuracy);
    },function(){
        console.log("geolocation not available")
    });

Learn more about HTML5 Geolocation. Geolocation Tutorial


webcam API using mediaDevices.getUserMedia

JavaScript Webcam API is used using navigator.mediaDevices.getUserMedia interface which provide access to device media including camera and mic. We can user this interface to open webcam in javascript or mic in javascript.



var constraints = {
    audio: false,
    video: true
};
navigator.mediaDevices.getUserMedia(constraints).
then((mediaStream)=>{
        document.querySelector("video").srcObject=mediaStream;
        document.querySelector("video").play()
}).
catch(function(err){ console.log(err)});


    var constraints = {
        audio: true,
        video: false
    };
    navigator.mediaDevices.getUserMedia(constraints).
    then((mediaStream)=>{
            document.querySelector("audio").srcObject=mediaStream;
            document.querySelector("audio").play()
    }).
    catch(function(err){ console.log(err)});