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

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:

    <h1 id="displayName">(to be replaced by user's display name)</h1>
            function (name) {
                document.querySelector("#displayName").textContent = name;

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


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

Comments (0)

Skip to main content