简体   繁体   中英

Is there a way to display the current username using JavaScript and HTML?

username of an OS can be shown in mostly all programming languages that I know. But is there a way I can display the name of the current user to the browser using JavaScript and HTML?

I have found similar questions over here , but the OS I use (GNU/Linux, DragonflyBSD, and Android) shows ReferenceError: ActiveXObject is not defined to the answers.

Yes, I have had a similar problem to solve a few years back. Using the Internet Explorer it is still possible to apply an ActiveX method to get the user name. Unfortunately (or fortunately, depending on your point of view) these methods are deactivated by default and have to be re-activated by the user (internet settings in the browser).

As end-of-life for the Internet Explorer is "in sight" I don't recommend going this way. Also, as the Internet Explorer is "different" (to put it mildly) from most other browsers.

As a work-around I defined a little token generator program (written in C), grabbing the user ID, encrypting it in combination with a time stamp information and send it to a corresponding PHP page. This receiving page decrypts the token, checks for a valid time stamp and user name, stores that in the current session and forwards the user to the desired target page.

It sounds to me that you will be using your page in a corporate environment, therefore the distribution of such a token generator program might be a solution for you. I can report that our users have accepted this makeshift "single-sign-on"-solution, as it frees them from loggin on with user name and password.

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