Javascript 环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3770446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:04:35  来源:igfitidea点击:

Javascript environment variables

javascript

提问by t0mcat

Could you please tell me, if it's possible to read Environment Variables using Javascript from a page running on Firefox.

您能否告诉我,是否可以从 Firefox 上运行的页面中使用 Javascript 读取环境变量。

采纳答案by Josh

Short answer: No.

简短的回答:没有。

Long answer: Maybe. If you mean system environment variables, there isn't (that I'm aware of) any way to do that via straight JavaScript. You can access a number of system information through JavaScript though. Check this page out for some examples:

长答案:也许吧。如果您的意思是系统环境变量,那么(我知道)没有任何方法可以通过直接的 JavaScript 做到这一点。不过,您可以通过 JavaScript 访问许多系统信息。查看此页面以获取一些示例:

http://www.docsteve.com/DocSteve/Samples/JS/javascript_env.html

http://www.docsteve.com/DocSteve/Samples/JS/javascript_env.html

This shows how to get the underlying OS/platform, Depending on exactly what you're looking for, this may not work. It's possible via other methods, like creating an ActiveX object and using that. However, this requires additional steps on the user end (like installing/authorizing ActiveX).

这显示了如何获取底层操作系统/平台,具体取决于您要查找的内容,这可能不起作用。可以通过其他方法实现,例如创建 ActiveX 对象并使用它。但是,这需要在用户端执行额外的步骤(例如安装/授权 ActiveX)。

I think this is a security feature, separating the system from the browser, therefore it can be difficult (or impossible, depending on your requirements).

我认为这是一项安全功能,将系统与浏览器分开,因此这可能很困难(或不可能,取决于您的要求)。

回答by Matt Ball

No. JavaScript is sandboxedto prevent this sort of thing.

不。JavaScript 被沙盒化以防止这种事情。