简体   繁体   中英

Display Window username with javascript

I want to retrive login window user name and display in Browser. Can java script be used for the same?

I think you can using an ActiveX control (ActiveXObject("wscript.network")) example:

var ActiveX=new ActiveXObject("wscript.network");
alert(ActiveX.username);
alert(ActiveX.computername);
alert(ActiveX.userdomain);
<script type="text/javascript" language="javascript">   

var objUserInfo = new ActiveXObject("WScript.network"); 
document.write(objUserInfo.ComputerName); 
document.write(objUserInfo.UserDomain); 
document.write(objUserInfo.UserName);   

</script>

I strongly doubt that Javascript has the power to do that as that would be considered exploitable and be a security problem. Javascript runs in a sandbox and has no access to any client properties other than the browser provides through the document and window objects.

However, you could use ActiveX objects or Kerberos/NTLM authentication to pass the user name from your server-side script back to the client and thus into javascript. Both these options will only work in Internet Explorer.

If you mean the HTTPAuth login it is also the easiest way to send the username back to your client using the server-side scripts as the authentication has been required/initialized by the server side and javascript has no direct access to there.

Javascript is a clientside browser language and has and should have nothing to do with the OS, so that won't work ... :)

EDIT: @thomas try to be more specific ... you want to build a plattform where users can login? then use a database where you store the users. Why do you need there windows login?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM