Skip to main content

Posts

Showing posts with the label visitor’s

Battery Status of your Visitor’s Mobile Phone

When someone visits your website, you can easily retrieve information about the charge level of their mobile or laptop�s battery through the Battery Status API. Here the source code: <!DOCTYPE html> <html> <head> <title>Battery Status API Example</title> <script> window.onload = function () { function updateBatteryStatus(battery) { document.querySelector(#charging).textContent = battery.charging ? charging : not charging; document.querySelector(#level).textContent = battery.level; document.querySelector(#dischargingTime).textContent = battery.dischargingTime / 60; } navigator.getBattery().then(function(battery) { // Update the battery status initially when the promise resolves ... updateBatteryStatus(battery); // .. and for any subsequent updates. battery.onchargingchange = function () { updateBatteryStatus(battery); }; battery.onlevelchange = function () { updateBatteryStatus(battery); }; battery.ondischargingtimechange = funct...