Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

When you have Microsoft Office Communicator or Lync installed, and you visit a SharePoint site, you will get these presence indicators next to peoples’ names

Presence Control

These indicators (or jelly beans as they are affectionately called) show whether the person is available, in a meeting, out of the office, on a call, etc. When you hover over them, they provide details about the person

Presence Details Menu

In SharePoint 2007 (or any other web page), whenever I needed to display a presence icon in custom code, I just use the following HMTL/CSS/JavaScript:

<script type="text/javascript" src="http://sharepointsite/_layouts/1033/init.js">
</script>
<script type="text/javascript" src="http://sharepointsite/_layouts/1033/core.js">
</script>
<style type="text/css">
img.presenceIndicator
{
   border-style:None;
   height:12px;
   width:12px;
   border-width:0px;
   vertical-align: middle
}
</style>
<span>
   <img id="uniqueID" onload="IMNRC('jadams@example.com', 
   getElementById('uniqueID'))" ShowOfflinePawn="1" 
   src=http://sharepointsite/_layouts/images/blank.gif 
   class="presenceIndicator"/>

   <a href="someCustomUserProfilePage.aspx?UserID=adamsjl">Adams, Jacob L.</a>
</span>

Print | posted on Tuesday, May 3, 2011 12:57 PM

Comments on this post

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
where should i post this code??
Left by unnie on Aug 31, 2011 1:53 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi Jacob

Thanks for the code example. It was pretty straightforward and easy to implement.

Couple of points I would like to add:

1) In below code snippet:
onload="IMNRC('jadams@example.com',
getElementById('uniqueID')" ShowOfflinePawn="1"

It seems that closing bracket for IMNRC function is not there, adding that worked for me.

2) In my hurry to try out the code I missed adding the span tag and due it the presence icons changed on status change but the hover menus did not work. On checking the js files I realized that the mouseover and mouseout events are defined for the span and embedding the img tag within the span is mandatory.

Once again thanks for this pretty useful example.

With Regards
Prakash Sobhani
Left by Prakash Sobhani on Oct 28, 2011 9:50 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi Jacob,

Thanks for your code snippet.

Could you please confirm, whether the above code will support for IE 8, if not which is the preferred version in IE.

Thanks in advance

-Rajesh
Left by Rajesh kumar on Nov 01, 2011 5:28 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi,
want to try this out... but where do I find the
init.js and the core.js?
and what was the blank.gif used?

Thanks
Brian
Left by Brian on Feb 20, 2012 9:14 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
@Unnie, this code would go on whatever page you want to include a presence indicator

@Prakash, thanks for the catch on the code. I updated it include the extra closing parenthesis.

@Rajesh, I've been able to use the above code snippet in IE6-9. Because of the ActiveX integration, it doesn't work in Chrome, FireFox, etc. though.
Left by Jake on Feb 20, 2012 9:48 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
@Brian, if you have a SharePoint server, the init.js and core.js files should be located in the corresponding locations mentioned above (note you'll need to change the name of the server to match your SharePoint server).

If you don't have a SharePoint server, you could try finding a publicly accessible one and downloading the files. One example I found after some quick searching was http://www.criver.com/en-US/Pages/home.aspx (note that this is a 2010 site, but it should still work)

The blank.gif is just a blank placeholder image in case presence isn't loaded. I've also seen cases where people replaced the blank.gif with the image representing offline or unavailable.
Left by Jake on Feb 20, 2012 9:56 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
The added source will use OCS to show the presence status. But how about if I have my own presence server and want sharepoint to use my server to display the presence in the same manner as it shows the lync presence. What should I do to support such implemention? Should I hook the name.dll call and inject my dll code to return the presence? Please suggest.
Left by Ranjan on Jul 11, 2012 6:47 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
@Ranjan, Unfortunately I'm not very familiar with this type of scenario. Are you saying that you are using some method other than OCS/Lync to determine if someone is available? If that is the case, you may be better off creating your own custom control that looks like the standard presence control. To get some ideas you may want to look at

WPF presence controls

http://www.microsoft.com/en-us/download/details.aspx?id=21648

Lync SDK

http://www.microsoft.com/en-us/download/details.aspx?id=18898
Left by Jake on Jul 11, 2012 8:39 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi,

When I implement this code I get the OCS presence indicator icons (circle) and the OCS drop down to show details, how do I get the Lync interface on icons and detail window?

I added our sharepoint server 2010 to above code.

Best regards
Martin
Left by Martin on Jul 12, 2012 11:34 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
@Martin, Almost all of the heavy lifting for displaying the icons and the details window is handled by the product installed on the end-user machine. Therefore, if you have Communicator installed on your machine, you should get the Communicator icons/popup. I upgraded to Lync and I have the new icons/pop without changing any of the HTML and JavaScript.
Left by Jake on Jul 12, 2012 12:16 PM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi Jacob,

Yes, I have Lync 2010 installed on my machine, still the old OCS icons, also when I visit our sharepoint sites I see the OCS icons and details.

Any idea?

Best regards
Martin
Left by Martin on Jul 14, 2012 8:09 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
1) How can the presence show automatically on page load, instead of on hover ?

2) Code above works. If placed in iframe in a server in a different domain, presence no longer appears. How restore presence indicator?
Left by DavidC on Jul 22, 2012 1:42 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
How to achive the same behaviour in ASP.NET web application?
Left by Pradeep on Jul 23, 2012 4:16 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Different domain not a problem - ignore 2) in comment above.

With iframe, presence icon appears in different location away from iframe (top left of screen instead of around center middle where the iframe is located). How can one adjust the position of the prsence icon? So I suppose I need to get the x and y coords of the iframe and then apply these to the presence icon ? Or, what is the id or class of the presence icon, so I could add CSS manually ?
Left by DavidC on Jul 25, 2012 5:44 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Really struggling to get this to work.
Have tried using local copies of the SP scripts, referencing them as our SP server.

Tried a variety of things for sip too.

Thought perhaps it might be a cross domain issue, but can't get it to work localhost, dev server or live server.

Is there a way to debug and step through the IMNRC function call?

Really grateful of any suggestions.

Such a pity that the Lync SDK only supports Silverlight and MVC apps and not good old asp.net web forms. :(
Left by Richard on Sep 13, 2012 10:53 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
How can it be done through c sharp and put it into sharepoint site?
Left by shruti on Feb 22, 2013 12:59 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi, what would you use in order to show the prescence indicators on chrome and firefox?
Thanks!
Left by Yael on Apr 15, 2013 1:03 PM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
DavidC, I haven't tried making the details show up automatically so I not sure if something exists in the API to do this or not.

As far as the iframe issue, we've run into that as well. The issue is that the code that calculates the x and y coordinates fails to take into account that it's in an iframe. For our situation, it was easier to change things not to use an iframe that to try to fix the positioning code.
Left by Jake on Apr 18, 2013 1:40 PM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Richard,
If my memory serves me correctly, either the init.js or core.js should contain the IMNRC call. You should be able to look at the code and/or hook up a JavaScript debugger to it. However, at a certain point in time, it drops into the ActiveX/COM control which would be a lot tougher to debug.
Left by Jake on Apr 18, 2013 1:44 PM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
shruti, anything that inserts the above code into the markup of the webpage should accomplish the task. The easier ways would be to put the code above into the markup of the aspx or ascx file. You could also put the markup into a literal control in the code behind.
Left by Jake on Apr 18, 2013 1:46 PM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Yael, as I mentioned in an earlier comment, due to the ActiveX ingration, this approach will on work in IE. There may be a solution out there that works in FireFox and Chrome, but I am not aware of one.
Left by Jake on Apr 18, 2013 1:50 PM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
I don't know where to write this script on. you can tell me clearly about it.
Left by veasna on May 09, 2013 9:37 PM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Can i use it in a html page?I am trying but still no success.
Left by Sumit on May 20, 2013 7:22 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
I had this working with Sharepoint 2007, but we've upgraded to 2010 and it no longer works. What do I need to change?

One difference is that I don't have the Adams, Jacob L. part. I'm just displaying the user name without the anchor tag. It worked without it before, but could this be the problem? If so, how do I determine what to use as the href and UserID?
Left by Azurescens on Jul 19, 2013 11:05 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Some user see a Jelly bean when hovering over the presence indicator and others see the contact card. Does anyone know why?
Left by Tiphanie on Aug 15, 2013 6:56 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi,
I need to show the lync status in asp.net application.what are the changes needs done in asp.net 3.5. kindly guide me.

Thanks in advance
Left by .NetEagel on Sep 10, 2013 10:26 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
.NETEagel, this is implemented in HTML and JavaScript. As long as you have copies of init.js and core.js you can reference, you should be able to use this code as is in ASP.NET, or any other server side framework for that matter.
Left by Jake on Sep 10, 2013 11:00 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi Jake,
Kindly forward the init.js, core.js as text files . so i can use it.

Left by .NetEagel on Sep 11, 2013 6:13 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
.NetEagel, I no longer have an active SharePoint 2007 server. Please see my earlier comment to Brian. You can get the .js files from any SharePoint site. If you don't have one, there are often several public sites you can find on the internet.
Left by Jake on Sep 11, 2013 6:31 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi Jake,
I have one question in showing the Lync status. I am showing the Lync status in radwindow. when we place the mouse on edge of image's border and do mouse wheel scroll,Lync icon is not moving along with window. It is staying the same place and window's screen is moves in background. it is not sync with window's moment.
Kindly guide us to resolve this image Position issue.

Thanks in advance
Left by .NetEagel on Sep 16, 2013 6:13 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
.NetEagel, I am unfamiliar with the radwindow control, but it sounds like it may be using an iframe to display things. If that is the case, please see my earlier comment to DavidC. For us, it was easier to not use an iframe than it was to try to fix the positioning code for the presence control.
Left by Jake on Sep 16, 2013 8:47 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi,

THanks for the example code you've provided.

I've managed to lcoate the JS files in my server and referenced these ojk but they lync status doesn't appear to work. Heres the code i've used.

<span>
<p> <img id="uniqueID" onload="IMNRC('sarah.Thomas@dcp.co.uk',
getElementById('uniqueID'))" ShowOfflinePawn="1"
src=http://sharepointsite/_layouts/images/blank.gif
class="presenceIndicator"/>
Sarah Thomas</p>
</span>

the user appears offline even though she is online. ANy thoughts? Any help you could give would be greatfully aprreciated
Left by Daniel on Nov 15, 2013 9:19 AM

# re: Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

Requesting Gravatar...
Hi Daniel,

Try removing the paragraph tag <p> from your <span> tag.

Also if you copy the .js files from your Sharepoint server then you must also copy the relevant images from _layouts/images/

Hope this helps.
Left by Murtieman on Dec 06, 2013 10:31 AM

Your comment:

 (will show your gravatar)