问题描述
我想知道如何在JavaScript中将当前用户的名称作为HTML文档的一部分.
I was wondering how I would get the name of the current user in JavaScript as part of an HTML document.
在Java中,可以键入 System.getProperty("user.name");
来实现.用JavaScript可以替代此方法吗?
In Java, one would type System.getProperty("user.name");
to achieve this. What is the alternative to this in JavaScript?
推荐答案
JavaScript在当前HTML文档的上下文中运行,因此除非它位于当前页面中,否则您将无法确定有关当前用户的任何信息对服务器端脚本进行AJAX调用以获取更多信息.
JavaScript runs in the context of the current HTML document, so it won't be able to determine anything about a current user unless it's in the current page or you do AJAX calls to a server-side script to get more information.
JavaScript无法确定您的Windows用户名.
JavaScript will not be able to determine your Windows user name.
这篇关于如何在JavaScript中获取当前Windows用户的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!