Javascript: Can you read the systems volume?
Asked Answered
S

3

21

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

Schlueter answered 20/3, 2011 at 12:53 Comment(3)
if you are trying to get the OS info via javascript you can use navigator.userAgentAttendance
HTML5 media allows you to set the volume on any media object. This might be useful.Denunciate
Possible duplicate of Javascript to detect system's volume (sound) and audio jack plugged inGabrielegabriell
D
14

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.

Dynasty answered 20/3, 2011 at 12:56 Comment(3)
I'm assuming the OP means volume as in sound, not as in partition. The answer is still the same though. :)Anadiplosis
actually, correct answer is yes, but requires additional software support (eg: scriptable plugin)Box
Thanks Andy, the point is to read if the user has volume to listen to audio, if it has volume then play audio, if no volume, then don't bother playing.Schlueter
H
8

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.

Harp answered 20/3, 2011 at 13:14 Comment(3)
About browser sandboxing - people install native applications in their smartphone / PC all the time, despite the fact that the applications can read data from the machine. I think tha knowing the system's audio volume can't do damage and can help a lot with websites functionality.Telekinesis
I also understand it's not possible today. But at least having a simple API that says if the computer has sound on or not is very useful for the user. Or something like a volume between 0 and, say 4 (using integers to prevent using for tracking/detection). If a site uses audio for it's main communication medium, the user will miss out of the experience. Being able to show an clear call to action about the users sound need to be turned on, is a big win for the UX of that kind of site/app.Abstemious
Ummm the camera :-) Javascript should totally allow this and show a popup to ask. It allows you to make sounds come out too, that's even more intrusive.. some random website could make a fart sound!Saporific
S
0

What about this? https://davidwalsh.name/javascript-volume It looks like you can do it by embedding an audio tag (even if you don't want to paste audio).

Saporific answered 30/1 at 7:21 Comment(1)
Linky-only answers are not good answers. Please add enough details in order to actually solve the issue at handEpistemology

© 2022 - 2024 — McMap. All rights reserved.