In Java, one would type
That said, the following code would allow you to get the logged in username, but it will only work on Windows, and only within Internet Explorer, as it makes use of ActiveX. Also Internet Explorer will most likely display a popup alerting you to the potential security problems associated with using this code, which won't exactly help usability.
As Surreal Dreams suggested you could use AJAX to call a server-side method that serves back the username, or render the HTML with a hidden input with a value of the logged in user, for e.g.
(ASP.NET MVC 3 syntax)
<input id="username" type="hidden" value="@User.Identity.Name" />
If the script is running on Microsoft Windows in an HTA or similar, you can do this:
var wshshell=new ActiveXObject("wscript.shell"); var username=wshshell.ExpandEnvironmentStrings("%username%");
I think is not possible to do that. It would be a huge security risk if a browser access to that kind of personal information
Working for me on IE:
...but ActiveX controls needs to be on in security settings.
©2020 All rights reserved.