Using jQuery to find the current logged in user SharePoint 2010

by Vipul Bhavsar 28. July 2011 05:21
JavaScript / jQuery on the page at either:
  • $(document).ready
  • _spBodyOnLoadFunctionNames
will not return the required result, since the menu elements we need to interrogate have not been rendered yet.
Solution:
  • Set a timer to keep running a particular function to wait until the menu is rendered
  • Stop the timer
  • Interrogate the DOM as required using jQuery
Code Example:
1 <script type='text/javascript'>
2
3 var timerHandle ="";
4 var currentWindowsAccount ="";
5 _spBodyOnLoadFunctionNames.push("runCustom");
6
7 function runCustom() {
8 timerHandle = setTimeout(getCurrentLoggedInUser, 10);
9 }
10
11 function getCurrentLoggedInUser() {
12 //Function requires jQuery
13
14 /* Retrieve the current logged in user from the My Profile option in **
15 ** the Welcome Menu (id=ID_MySiteLinksMenu) **
16 ** This needs a timeout to wait for the menu to be rendered via AJAX */
17
18 //Timers are expensive on client resources, clear at all opportunities
19 clearTimeout(timerHandle);
20
21 var welcomeMenuItems = $('#ID_MySiteLinksMenu'); //ie:menu with id='ID_MySiteLinksMenu'
22
23 if (welcomeMenuItems.length >0) {
24 var onmenuclickValue = welcomeMenuItems.attr("onmenuclick");
25 var onmenuclicksplit = onmenuclickValue.split("=");
26 var loggedInUserString = onmenuclicksplit[1];
27 var loggedInUserStringSplit = loggedInUserString.split("'");
28
29 currentWindowsAccount = loggedInUserStringSplit[0];
30 alert(currentWindowsAccount);
31 }
32 else {
33 //My Profile link has not been rendered yet, try again.
34 timerHandle = setTimeout(getCurrentLoggedInUser, 10);
35 }
36 }
37
38 </script>

Tags: , ,

jQuery | SharePoint 2010

Scrolling site title bar script

by Altaf Pinjari 27. April 2011 01:52

Copy and Paste below cod in website head section :

<head>
<title>Site Name &nbsp;&nbsp; ::: &nbsp;&nbsp;Welcome to A &nbsp;</title>

<script type="text/javascript" language="javascript">
var repeat=2 //enter 0 to not repeat scrolling after 1 run, othersise, enter 1

var title=document.title
var leng=title.length
var start=1
function titlemove() {
titl=title.substring(start, leng) + title.substring(0, start)
document.title=titl
start++
if (start==leng+1) {
start=0
if (repeat==0)
return
}
setTimeout("titlemove()",140)
}
if (document.title)
titlemove()
</script>

</head>

Tags: , , ,

jQuery

About Ignatiuz

Ignatiuz Technologies is an IT company offering technology solutions for customers keeping partner centric approach with a mantra "Compelling IT Solutions". The company is passionate to latest technologies & innovation. Our consulting led approach make our customers become partners & partner's transformation to global corporations.

Ignatiuz QR Code

Month List

Tag cloud