开发者

Javascript: Can you read the systems volume?

Is there any way to read the System's开发者_运维问答 (Linux, Windows, OS/X etc) volume with Javascript?

I don't need to set it, just read it?

thanks


I'm assuming you're talking about Javascript in a browser environment. In this case, the answer is clear, short and simple: No.

Clientside Javascript has no support for File IO operations.


However, in some browsers you can breach that rule by setting browser specific options. For instance, calling a Webkit based browser with the command-line argument --disable-web-security allows the browser to read a uri like file:///c/somefolder/. Mozilla offers this possibilty by editing the user ini plus a setting in about:config.


Update

I guess deceze's comment is correct and you really mean the "sound volume". In that case you can forget about the above text, but the answer is again no. There is no native Javascript interface to get and/or set that kind of OS setting.


Just to piggy back on @jAndy's answer: the whole point of a browser environment is that you can't do this. Would you trust a browser if you surf to a website, and the browser allows the website (via its JavaScript) to collect information about your computer, and then send to somebody who may mean you harm?

So, the answer "NO" is not only correct, it is a "MUST" in order for browsers to do anything more than trivial. Browsers (not JavaScript though -- don't shoot the messenger) are deliberately designed so that the answer to your question is NO.

Now, JavaScript as a language really doesn't prevent you from doing this. The browser disallows your access (via a process called "sandboxing"), not JavaScript.

What about IE and ActiveX controls?

IE allows users to install ActiveX controls that can have full rights to the system. In this case, JavaScript can easily create an ActiveX object and then do whatever they like to your computer (including FORMAT C:), depending on the rights given to the ActiveX control.

So, IE poses huge security risks by allowing web sites to download and install ActiveX controls on the client computer, sometimes with full access rights. Again, JavaScript is just the messenger here, not the culprit.

After note

I am NOT suggesting to you to write an ActiveX control that will download to a client's computer for you to then access information on their computer. We have a name for such programs (trojan horse/virus/malware), and a name for such actions (illegal hacking).

So, although I trust that you only want to read a client computer's information (not to control it in any way), please be glad that browsers (proper ones) are designed to stop you from doing that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜