使用 Javascript 读取环境变量

Reading environment variables with Javascript(使用 Javascript 读取环境变量)

本文介绍了使用 Javascript 读取环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从客户端操作系统的环境变量中读取系统时间.我在 Stackoverflow 上搜索,发现这是不可能的.但是,这些答案来自 2010 年,我想问一下自那以后是否有任何变化.

I need to read the system time from the environment variables on the client's OS. I searched on Stackoverflow and found that this isn't possible. However, those answers were from 2010 and I want to ask if anything has changed since.

是否有可能使用某种框架?还是 Javascript 仍处于沙盒状态并与操作系统断开连接?

Is it possible with some kind of framework? or Javascript is still sandboxed and cut off from OS?

推荐答案

szpic,如果 Javascript 没有从操作系统沙箱化,任何愚蠢的犯罪分子都可能进入您的计算机并控制.允许环境变量的级别太低了,永远不允许.

szpic, if Javascript were not sandboxed from the OS, any half-witted criminal could get onto your computer and take control. Allowing environmental variables is way too low level to ever be allowed.

看看你所有的环境变量,问问自己这个星球上的每个人是否都应该有权访问关于你计算机的所有数据.

Take a look at all of your environmental variables and ask yourself if everyone on the planet should have access to all that data about your computer.

如果您想使用 Javascript 执行此操作,则必须使用特殊的网络浏览器,例如 node-webkit.不过,它不会在任何普通的网络浏览器上运行,所以不要期望超过 0.0001% 的人会期望运行您的页面.

If you want to do this with Javascript, you'll have to use a special web browser, such as node-webkit. It isn't going to run on any normal web browser, though, so don't expect more than 0.0001% of the population to expect to run your page.

我不知道你的预期用途,但是一个技巧,就是加入一个环境变量,就是为你的 web 应用程序创建一个快捷方式,并将其作为 URL 参数包含在其中(至少在 Winblows 上).

I don't know your intended use, but one trick, to throw in an environmental variable, is to make a shortcut to your web application, and include it in there as a URL parameter (at least on Winblows).

http://myapp.com?computername=%COMPUTERNAME%

这篇关于使用 Javascript 读取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 Javascript 读取环境变量

基础教程推荐