Reputation: 2080
According to W3 Page Visibility specification and Mozilla's Page Visibility API documentation, the Page Visibility API supports detecting if a browser window is hidden because of the OS lock screen. Unfortunately, all of the examples I have found seem to indicate that this is not supported. I cannot get any example JS code or any of my JS code to report that the browser was hidden when I lock my screen (on Windows or OS X).
Some of the examples I have tried:
None of these report that the page was hidden when I lock my OS. Is this just not supported even though the documentation indicates otherwise?
Because I have to insert some code to be able to link to JSFiddle...
var results = document.getElementById('results');
function handleVisibilityChange() {
if (document.webkitHidden) {
results.innerHTML = results.innerHTML + 'Hidden.<br>';
} else {
results.innerHTML = results.innerHTML + 'Visible.<br>';
}
}
document.addEventListener("webkitvisibilitychange", handleVisibilityChange, false);
Upvotes: 4
Views: 386
Reputation: 734
It works on OSX with Safari 8. (For lock and screen saver)
However no browser I found works for Windows.
As of 27/04/2015
Upvotes: 4