简体   繁体   中英

How to get the windows (logged in) username in Firefox using Javascript

I am working on a very old web application(only for intranet usage). In the code, the developer is obtaining the logged in account via this

var wshNetwork = new ActiveXObject("WScript.Network"); document.getElementById('userId').value = wshNetwork.UserName;

This works only in IE. How can I get the logged in account in Firefox/chrome?

I have looked in to other thread (ex: Finding the currently logged in user from a Firefox extension ) but that's only for extension.

Are there any other ways to get the domain logged in username in Firefox/Chrome?

No, this is severely security-sensitive information - the main attack vector for compromising your computer. In IE it also only works for trusted websites such as localhost, or with special configuration for the local network - never on internet without additional configuration. Sandboxed JS will never be able to access this information - extensions are considered elevated.

This is something that I would do on server side. Providing you're using IIS, I would set the page to be using only Windows Authentication, read the current user on server side, and send it back to client via hidden field or javascript variable.

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