Very impressive, thank you so much! For me, and perhaps for others, it’s nice to still have code work for IE11 because it’s still used, although fading away slowly. Habits of using a particular browser for users can be hard to break.
Thanks for providing that to me, I really appreciate it. And again, thanks for @Paul_Wilkins help too. Both of you have impressive skills that I wish I had.
You wouldn’t be able to store the amount of time remaining in a long-term variable. You would need to calculate the amount of remaining time each second of the loop instead, as is done in post #44
That’s very interesting, I am going to evaluate that. And by the way, I have used the timer and like it very much and I really appreciate your efforts on this as well as @rpg_digital. Both very helpful.
Still a little confused on some of my research on mobile devices and if JS can run in background. I read some that say yes and many saying no. Can you clarify if in fact you can effectively run JS in the background and/or when the screen is off (perhaps that’s the same thing)?
So if let’s say you have a secure bank site and want to auto logoff after x mins, there is no guarantee that will 100% work in the background?
Also, if you can’t guarantee that it will work in the background, can you guarantee if coded probably, it won’t work? Meaning you don’t want it to continue running once it’s not an active screen?
Is it possible, that at the end of the countdown (00:00), it could trigger an AJAX response so I can send that information to the database? Using something like I do with links clicked, like this:
<script>
function loadXMLDoc(elementId, endpoint) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(elementId).innerHTML =
this.responseText;
}
};
xhttp.open("GET", endpoint, true);
xhttp.send();
}
</script>
document.addEventListener('DOMContentLoaded', function(event) {
window.setTimeout(function(event){
const clocklink = document.querySelector('#clocklink a')
// replace the surrounding anchor tag and content e.g. <a>text content</a>
// with just the text content
clocklink.outerHTML = clocklink.textContent
}, 2000 /* delay here in ms */)
})
or maybe add a class as well to indicate it has been disabled?
css
.disabled-link {
text-decoration: line-through;
}
javascript
document.addEventListener('DOMContentLoaded', function(event) {
window.setTimeout(function(event){
const clocklink = document.querySelector('#clocklink a')
clocklink.outerHTML = '<span class="disabled-link">' + clocklink.textContent + '</span>'
}, 2000 /* delay here in ms */)
})
document.addEventListener('DOMContentLoaded', function(event) {
window.setTimeout(function(event){
// this time selected the whole clocklink
const clocklink = document.querySelector('#clocklink')
clocklink.classList.add('hide')
}, 2000 /* delay here in ms */)
})