I'm having some issues regarding a function. I'm creating an application that when the phone is on low battery it automatically switches to darkmode. The issue is that when I switch html pages the 'deviceready' function keeps firing, so I keep getting a low battery alert on every page I load. Is it because I have the event listener as a global? If so.. where should I place it so it only runs once? Thanks much appreciated.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.addEventListener("batterystatus", onBatteryStatus, false);
}
function onBatteryStatus(status) {
console.log("Level: " + status.level + " isPlugged: " + status.isPlugged);
if(status.level < 15){
alert("Low Battery");
}
}