Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
Of course the JavaScript code above could be used in an external .js file as well.