📜 ⬆️ ⬇️

Take a javascript API; Come and find out more quickly that in our Firefox a battery has sat down! ...

As you know, W3C is working on a draft draft of the Battery API standard, the implementation of which will allow javascript in the browser to monitor the charge level of the battery in that mobile device (mobile phone, tablet, netbook, laptop, etc.) on which the browser is running.

We are talking about the appearance of the navigator.battery object with the properties of navigator.battery.charging (boolean; true if the device is recharged) and navigator.battery.level (a number from 0.0 to 1.0 , expressing the amount of battery charge relative to its maximum charge). Both properties are read only. This facility will also have events that allow you to monitor changes in battery status like this:

navigator.battery.addEventListener('chargingchange', function () { if (navigator.battery.charging) { console.log('     .'); } }, false); 

At the end of this fall (2011), the corresponding object (under the name navigator.mozBattery ) was added to the Firefox object model of the eleventh version (see bug 678694 ); its appearance on schedule should be expected in the middle of March of the future (2012) of the year, and we will see the beta in early February. I look forward to, because the mobile Firefox eleventh version in general promises to shine a lot of changes compared to the tenth.
')
Details about the implementation of the new object are set out in MozillaWiki . It appears that there will be only two events at the beginning : chargingchange (when the battery starts or, on the contrary, stops charging) and levelchange (when the charge level changes by 1%).

In the draft of the W3C, two additional properties ( chargingTime and dischargingTime ) are already designed to estimate the estimated time remaining until the battery is fully charged (or critical), and with them events ( onchargingtimechange and ondischargingtimechange ) in case this rating changes.

Source: https://habr.com/ru/post/135474/


All Articles