Company News

SharePoint 2010 Get Current Username / Logged in User

December 2, 2011
Have been exploring the SharePoint Client Object Model and in particular the Javascript Object Model

While there are methods to get the current user info, you can also simply borrow the logged in username from the top right of the screen:

[javascript]

<script type="text/javascript">// <![CDATA[
var Username = document.getElementById("zz16_Menu").innerHTML ;
var end = Username.indexOf("<");
var nameOnly = Username.substring(8, end);
document.write(nameOnly);

// ]]></script>

[/javascript]

This technique is a little complex for my liking however, so here’s a snappier way to grab the current login name (using Jquery):

[javascript]

var Username = $("#zz16_Menu").text();
document.write(Username);

[/javascript]

Note that the #zz16

To see the full content, share this page by clicking one of the buttons below

Leave a Reply

Keith Tuomi

Keith Tuomi

Powered by...

itgroove Corporate Profile
Connect With Us