I have a webpart page with two webparts. One is a calendar and the other is a hidden content query webpart that references a file that is used to style (apply color coding) to the calendar entries.

My problem is that when the user goes to the page the calendar ribbon is not available. This occurs because there are two webparts on the page and the ribbon doesn't know which one it needs to use to generate its content. How can I force my calendar control to always be selected when the page loads so that my users have access to the calendar ribbon without having to click on the calendar?

1 Answer 1


1 Make sure jQuery is present and working on the page in question - I found I had to download from the jQuery site (http://docs.jquery.com/Downloading_jQuery) and use a relative link. Using the CDN hosted jQuery didn't work for me.

    <script src="/Shared%20Documents/jquery.js" type="text/javascript"></script>

This link was useful - http://www.threewill.com/2012/01/adding-jquery-to-sharepoint/

2 Add a content editor web part to the page with this code:

 <script language="javascript" type="text/javascript">

    $(document).ready(function  () {

       ExecuteOrDelayUntilScriptLoaded(ShowCalendarRibbon, "sp.ribbon.js" );

       function  ShowCalendarRibbon() {

          try  {

             var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
             if(elem != null) {
                var theEvent = new Array()
                theEvent["target"] = elem
                theEvent["srcElement"] = elem

          catch  (e) {
             alert("Problem initializing ribbon");




N.B. Add this code through the HTML source of the content editor:

enter image description here

You may need to change the ID for the Calendar depending on the web parts on your page, but mine was - MSOZoneCell_WebPartWPQ2

Set "Chrome Type" to "None" to hide the content editor on the page.

This post provided most of the info - Select the ListView Web Part Automatically on AllItems.aspx

This post also helped - http://ikarstein.wordpress.com/2010/06/15/how-to-activate-sharepoint-ribbon-tab-by-javascript-code/

Using a query string is also an option http://www.sharepointdevelopment.me/2010/11/set-active-ribbon-tab-from-querystring/ - E.g. ?InitialTabId=Ribbon.Calendar.Calendar - but this didn't seem to work for me

  • I've noticed that this doesn't work on some pages where I've added more javascript through other content editors. On those pages it will select the "Calendar Tools" tab on load but the "Calendar" sub tab will not be selected. Are there any timing issues with this code?
    – skeletank
    Commented May 30, 2012 at 15:40
  • Hi @skeletank, I haven't been able to replicate your issue, are you able to post some of the other javascript you have on your pages to see if I can get the same thing to happen?
    – junkrig
    Commented May 31, 2012 at 1:04
  • Using a query string works for me. ?InitialTabId=Ribbon.Calendar.Calendar Commented Oct 5, 2022 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.