Hello.
I know that this topic was discussed in this post and in this post and they are marked as Solved, but for me it is not clear yet.
I know that @hhuman posted the solution but I was trying to workaround and to have the webpage / screen in the app activ as the user open the screen without any interaction.
So, the idea is to have the screen active as it opens.
I have removed the button for user interaction and I have the app screen full alive, without any enabling button, BUT it is not working if the user has the phone on Low Battery Mode…
AS I use the version from @hhuman with the button that it is enabled by user, the screen stays alive even if the phone it is on Low Battery Mode.
WHY?
- Does anybody has idea how to make it to work even on Low Battery?
- Can somebody provide me a solution to have the enabling button under a Thunkable button?
Here is the code from my version, without button with onload function:
<html>
<head>
<title>NoSleep.js - Simple Test Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="NoSleep.min.js"></script>
<script>
function myFunction() {
var noSleep = new NoSleep();
noSleep.enable(); // keep the screen on!
document.body.style.backgroundColor = "green";
}
</script>
</head>
<body onload="myFunction()">
<h1>NoSleep Test Page</h1>
</body>
</html>
And this is the code from the original version:
<html>
<head>
<title>NoSleep.js - Simple Test Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>NoSleep Test Page</h1>
<script src="NoSleep.min.js"></script>
<input type="button" id="toggle" value="Wake Lock is disabled" />
<script>
var noSleep = new NoSleep();
var wakeLockEnabled = false;
var toggleEl = document.querySelector("#toggle");
toggleEl.addEventListener('click', function() {
if (!wakeLockEnabled) {
noSleep.enable(); // keep the screen on!
wakeLockEnabled = true;
toggleEl.value = "Wake Lock is enabled";
document.body.style.backgroundColor = "green";
} else {
noSleep.disable(); // let the screen turn off.
wakeLockEnabled = false;
toggleEl.value = "Wake Lock is disabled";
document.body.style.backgroundColor = "";
}
}, false);
</script>
</body>
</html>
Any idea?
Thank you!