用JavaScript读取环境变量 [英] Reading environment variables with Javascript

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

问题描述

我需要从客户端操作系统上的环境变量读取系统时间。我在Stackoverflow上搜索,发现这是不可能的。但是,这些答案是从2010年开始的,我想询问是否有任何变化。



可以用某种框架吗?或者Javascript仍然是沙盒,并从操作系统中断?

解决方案

szpic 如果Javascript没有从操作系统中沙箱,任何半弱的犯罪分子都可以进入您的计算机并进行控制。允许环境变量太低级别永远不允许。



查看所有的环境变量,并问自己,地球上的每个人都应该可以访问所有关于您的计算机的数据。






如果要使用Javascript执行此操作,则必须使用特殊网页浏览器,例如 node-webkit 。不过,在任何正常的网络浏览器上都不会运行,所以不要指望超过0.0001%的人口来运行您的页面。






我不知道你的预期用途,但是一个窍门是抛出一个环境变量,就是给你的Web应用程序一个快捷方式,并把它作为一个URL参数至少在Winblows上)。

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


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.

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

解决方案

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.


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.


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读取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆