I want to show the battery status of client's system and a clock in a widget in my webpage If it is a Laptop.
If it is a desktop, I don't want to show the battery status.
The clock widget is working fine.
Also I am able to get the battery details by using navigator.getBattery()
.
But if it is Desktop, I don't want to show the widget.
So, How to detect whether the client using Desktop or Laptop using JavaScript?
The below is the contents of navigator
but it didn't have details to detect whether it is a Laptop or Desktop.
console.log(navigator);
{
"vendorSub": "",
"productSub": "20030107",
"vendor": "Google Inc.",
"maxTouchPoints": 0,
"hardwareConcurrency": 4,
"appCodeName": "Mozilla",
"appName": "Netscape",
"appVersion": "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
"platform": "Win32",
"product": "Gecko",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
"language": "en-GB",
"languages": [
"en-US",
"en"
],
"onLine": true,
"cookieEnabled": true,
"doNotTrack": null,
"geolocation": {
"getCurrentPosition": function getCurrentPosition() { [native code] },
"watchPosition": function watchPosition() { [native code] },
"clearWatch": function clearWatch() { [native code] }
},
"mediaDevices": {
"enumerateDevices": function enumerateDevices() { [native code] },
"getSupportedConstraints": function getSupportedConstraints() { [native code] },
"getUserMedia": function getUserMedia() { [native code] },
"addEventListener": function addEventListener() { [native code] },
"removeEventListener": function removeEventListener() { [native code] },
"dispatchEvent": function dispatchEvent() { [native code] }
},
"plugins": {
"0": [object Plugin],
"1": [object Plugin],
"2": [object Plugin],
"3": [object Plugin],
"4": [object Plugin],
"length": 5,
"item": function item() { [native code] },
"namedItem": function namedItem() { [native code] },
"refresh": function refresh() { [native code] }
},
"mimeTypes": {
"0": [object MimeType],
"1": [object MimeType],
"2": [object MimeType],
"3": [object MimeType],
"4": [object MimeType],
"5": [object MimeType],
"6": [object MimeType],
"length": 7,
"item": function item() { [native code] },
"namedItem": function namedItem() { [native code] }
},
"webkitTemporaryStorage": {
"queryUsageAndQuota": /**id:16**/ function queryUsageAndQuota() { [native code] },
"requestQuota": /**id:17**/ function requestQuota() { [native code] }
},
"webkitPersistentStorage": {
"queryUsageAndQuota": /**ref:16**/,
"requestQuota": /**ref:17**/
},
"serviceWorker": /**error accessing property**/,
"getBattery": function getBattery() { [native code] },
"sendBeacon": function sendBeacon() { [native code] },
"requestMediaKeySystemAccess": function requestMediaKeySystemAccess() { [native code] },
"getGamepads": function getGamepads() { [native code] },
"webkitGetUserMedia": function webkitGetUserMedia() { [native code] },
"javaEnabled": function javaEnabled() { [native code] },
"vibrate": function vibrate() { [native code] },
"requestMIDIAccess": function requestMIDIAccess() { [native code] },
"credentials": {
"get": function get() { [native code] },
"store": function store() { [native code] },
"requireUserMediation": function requireUserMediation() { [native code] }
},
"storage": {
"persisted": function persisted() { [native code] },
"persist": function () { [native code] }
},
"permissions": {
"query": function query() { [native code] }
},
"presentation": {
"defaultRequest": null
},
"getUserMedia": function getUserMedia() { [native code] },
"registerProtocolHandler": function registerProtocolHandler() { [native code] },
"unregisterProtocolHandler": function unregisterProtocolHandler() { [native code] }
}