开发者

Detect if no system activity from browser (including activity outside the browser)

开发者 https://www.devze.com 2023-01-17 03:17 出处:网络
I need to detect if the is no user activity in the system (e.g. what screensaver does) - all from a web browser.

I need to detect if the is no user activity in the system (e.g. what screensaver does) - all from a web browser.

As far as i'm aware it is not achievable using pure JavaScript. There is a library for detective idle input within a browser though: jquery-idletimer-plugin

For system idle events I'm thinking ActiveX control or SilverLight.

Has anybody done this before? Any recommendations?

UPDATE: I think a sensible solution would be to have a helper app that's running on user's computer and sends idle events to the browser. So the new question is how can i send a me开发者_高级运维ssage to an open browser (webkit based, with my web app open) from a Windows app so that it can be picked up from JavaScript?


There won't be any reliable way of doing this ever. As Denis said you can't do it with Silverlight and ActiveX works only in Internet Explorer, so in case this is a crucial part of your application then you should better have some really good reasons for me to use it, otherwise why should I start up IE(and a machine with Windows on it in my case)?

Hell, even if I would be using IE, why should I open up a site that's monitoring the activity OUTSIDE of my browser? Who's telling me that you're not logging my keystrokes at the same time, huh?

There's no good reason on this planet for doing such a thing from within a Browser, you're essentially destroying all the trust in your application by circumventing the Browser's security model. The sandbox is there for good reasons, otherwise surfing the web would be just as dangerous as downloading random files and executing them...

So whatever you're trying to achieve with this, please give up on it and search for a better solution that A: Works cross browser/platform and B: Doesn't make your App look like it could steal my passwords any day.


If you really need to this, (I'm hoping its for a client who asked for a feature like this) you should write your own browser (C# allows you to just drop a web browser control on a form with only a little customization needed) and have your users use that browser (which you can then use to detect idle status using the operating system features.

Again this is under the assumption that you have a client that asked for this and not for a project that will be out in the wild, otherwise what Ivo said is completely true, I wouldn't want to download a brand new browser just to run a simple website.


Sorry to post in this old post, but there's a way to workaround this issue, the downside is that it requires JavaScript, but probably can use any other user-side language as well.

With JS you can set a timeout to an specific time example 640000 for 10 minutes. Then cancel the timeout every time there's a interaction with the page (click, scroll, etc..) and set it again. If the user stop interacting with the page for a 10 minutes then an alert or a function can be executed. Either closing the session with ajax or just an alert.

This is useful when you don't have control of your serve side session time out, and there's a sensitive process going on, like an order form that might corrupt your data if it submitted after the session is closed by the system. You can create a function in ajax that submit the form to save the data entered by the user without submitting before idling. Not good for educational websites, just for website that requires input from user when a process has been started.

Hope this gives an idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消