問題描述
我需要從客戶端操作系統的環境變量中讀取系統時間.我在 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 讀取環境變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!