问题
Can i get the username of the currently looged in person using applets. If yes, how can i use the applet in my dynamic web project? I know in I.E we can do like this
var objUserInfo = new ActiveXObject("WScript.network");
document.write(objUserInfo.ComputerName+"<br>");
document.write(objUserInfo.UserDomain+"<br>");
document.write(objUserInfo.UserName+"<br>");
var uname = objUserInfo.UserName;
alert(uname);
but i want it using applet so that it will work in any browser.
回答1:
Be aware that this is in fact an attempt to circumvent the browser security. look at the answer to this similar (but not excactly the same) question. http://www.coderanch.com/t/243316/Applets/java/windows-NT-login-applet
- ActiveX will not run properly in Chrome / Firefox.
- Javascript won't (due to security reasons) allow you to get that information from the operating system.
- Flash is cross browser, and can be used for this, but it is difficult to get around chromes sandbox.
so my best suggestion is java.
Here is a similar question that is answered on why you can't without an applet. https://security.stackexchange.com/questions/36728/can-your-windows-or-linux-username-be-exposed-to-websites
And the provided link from an answer to another similar question points to a java solution, but there are limits to the success: http://www.rgagnon.com/javadetails/java-0441.html
However I think you should start from there, and then post a solution here when it works ;)
See the problem here is that when the applet tries to interact with local resources the browser must allow it, or block it.. Security settings in IE, may prevent that if set to high, and Chromes sandbox may block it if you do it wrong. I don't know of problems with Firefox or Safari, but I guess you'll find them when testing...
Good luck.
来源:https://stackoverflow.com/questions/29598884/get-client-windows-username