Wednesday, June 12, 2013

Java Script: Get user name of login person

 

Sometime you may have requirement to show message like Welcome User for some type of application and If that application is not authenticated then we can pull user name from window credentials using java script.

<f:view>
    <script type="text/javascript">
      function currentUser() {
        var ntw = new ActiveXObject("WScript.Network");
        alert(ntw.UserName);
      }
    </script>
    <html>
      <head>
        <meta http-equiv="Content-Type"
              content="text/html; charset=windows-1252"/>
        <title>untitled1</title>
      </head>
      <body onload="currentUser();">
        <h:form></h:form>
      </body>
    </html>

No comments:

Post a Comment