最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript code to prevent screensaver from starting - Stack Overflow

programmeradmin7浏览0评论

I am pletely new to javascript programming and I have a question that I didn't manage to find an answer for anywhere.

I have recently put together a simple slideshow to view the photos remotely that I host on my home puter. This by itself works fine. The problem I run into is that when I'm viewing photos I don't interact with the hardware, which after some time causes the monitor to switch off. This is particularly annoying when watching photos on my mobile phone.

My question is: is there a way to prevent this from happening? I am thinking in the direction of faking a mouse or other event every time I refresh the photo, but I have no clue how to do that and if it is possible.

Any help is greatly appreciated!

I am pletely new to javascript programming and I have a question that I didn't manage to find an answer for anywhere.

I have recently put together a simple slideshow to view the photos remotely that I host on my home puter. This by itself works fine. The problem I run into is that when I'm viewing photos I don't interact with the hardware, which after some time causes the monitor to switch off. This is particularly annoying when watching photos on my mobile phone.

My question is: is there a way to prevent this from happening? I am thinking in the direction of faking a mouse or other event every time I refresh the photo, but I have no clue how to do that and if it is possible.

Any help is greatly appreciated!

Share Improve this question asked Dec 21, 2010 at 21:47 gertjangertjan 8511 gold badge9 silver badges16 bronze badges 5
  • 5 The question is interesting, but along with many limitations of JavaScript, it can't be done. Why? Security. As there are good people that want to use this code wisely, there are opposites that will harm. – JCOC611 Commented Dec 21, 2010 at 21:58
  • It's in the JavaScript manual next to the functions that give the user an electric shock if they try turning the puter off... – Pete Kirkham Commented Dec 21, 2010 at 22:42
  • Hm, not possible then, that's too bad. I suppose that only leaves John's solution and switch off power saving manually. :\ Well thanks everybody for answering so rapidly! – gertjan Commented Dec 23, 2010 at 8:22
  • 1 This is not as unreasonable as you might expect; for example, there are already APIs for controlling screen brightness and orientation: developer.mozilla/en-US/docs/Web/API/Screen – Cauterite Commented Dec 23, 2016 at 9:52
  • Possible duplicate of stackoverflow./questions/11529247/… – MadeInLagny Commented Jan 2, 2020 at 14:01
Add a ment  | 

5 Answers 5

Reset to default 12

Over the decade since this question was originally asked JavaScript has grown to provide much of the OS functionality (usually in a secure manner). The "wake lock" functionality is slowly being implemented. Currently there is a draft for the navigator.getWakeLock interface: https://www.w3/TR/wake-lock/#conformance

Chrome (https://developers.google./web/updates/2018/12/wakelock) and Mozilla (https://developer.mozilla/en-US/docs/Web/API/Screen_Wake_Lock_API) are considering it in various manners.

No. JavaScript on the browser cannot interact with the underlying system. Simulating keystrokes in the browser will not stop the screen saver from turning on. This is for security reasons, so that malicious code can't harm the system when you visit a web page.

Link on JavaScript Security

The modern JavaScript security model is based upon Java. In theory, downloaded scripts are run by default in a restricted “sandbox” environment that isolates them from the rest of the operating system. Scripts are permitted access only to data in the current document or closely related documents (generally those from the same site as the current document). No access is granted to the local file system, the memory space of other running programs, or the operating system’s networking layer. Containment of this kind is designed to prevent malfunctioning or malicious scripts from wreaking havoc in the user’s environment. The reality of the situation, however, is that often scripts are not contained as neatly as one would hope. There are numerous ways that a script can exercise power beyond what you might expect, both by design and by accident.

No, JavaScript cannot affect hardware or operating system. Just turn off monitor power saving settings until you're done with the slideshow.

Yes, It's possible now :)

Just use NoSleep.js library: https://github./richtr/NoSleep.js

It's working form me with Reveal.js slides on my Android Tablet

You could do it with a console application written in c# that interacted with the os

since js is a client side browser language it can only interact with the browser/bowser

发布评论

评论列表(0)

  1. 暂无评论