HTML5 Zone is brought to you in partnership with:

Prior to joining Microsoft, J. "Michael" Palermo IV served as a Microsoft RD and MVP based in Phoenix, AZ. Michael is a Microsoft Certified Trainer (MCT) and maintains a number of industry related certifications. Michael is a published author on web technologies, and currently writes articles for DevProConnections regarding HTML5 technologies. Michael is invited to speak at developer events around the world. Michael is a DZone MVB and is not an employee of DZone and has posted 3 posts at DZone. You can read more from them at their website. View Full User Profile

JavaScript for Windows 8 Apps: How to Access the User’s Display Name

10.03.2012
| 1503 views |
  • submit to reddit

Need to know the display name of the user currently logged in to Windows 8?  The task is easy!

To demonstrate, I created a new “Blank App” JavaScript project in Visual Studio 2012.  In the default.html file, I replaced the contents of the <body> tag with the following:

<body>
    <h1 id="displayName">(to be replaced by user's display name)</h1>
    <script>
        Windows.System.UserProfile.UserInformation.getDisplayNameAsync().then(
            function (name) {
                document.querySelector("#displayName").textContent = name;
            }
        );
    </script>
</body>

When I run the application, my <h1> contents contain my display name.

SNAGHTML6b4d0e

Of course the JavaScript code above could be used in an external .js file as well.

 

 

Published at DZone with permission of Michael Palermo, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)