JonoT
JonoT

Reputation: 73

How to detect desktop is locked in javascript

A simple question that I just can't find an answer for. I want to stop a periodic AJAX call when the user has wandered away and locked their PC. I don't need it to be every OS compatible or every browser (Chrome and IE would be good).

setInterval just doesn't seem to stop when locked and AJAX is also not prevented. The visibilitychange event seems to think that the tab is visible unless you switch to another tab.

I have stated javascript, but I only care that it can be done within the browser without asking the user.

Edge does seem to indicate it is hidden when locked, so I'm ok with that browser.

Thanks

Upvotes: 3

Views: 5632

Answers (2)

bhspencer
bhspencer

Reputation: 13570

In your javascript it is not possible to detect if the OS UI has locked. The browser sand box prevents this kind of access to OS resources for security reasons. You would need to write a browser plugin to do this.

Upvotes: 2

fixmycode
fixmycode

Reputation: 8506

You can use the Idle.js library to detect if the user is looking away from the browser window or is inactive (his input devices are inactive).

Whatever the case, there's not a reliable way to get the OS or the screen saver state from the browser

Upvotes: 3

Related Questions