Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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
                WpClick(theEvent)
             }        

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

       };

    });

</script>

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

share|improve this answer
    
Thanks! This worked perfectly. –  skeletank May 16 '12 at 13:04
    
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 May 30 '12 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 May 31 '12 at 1:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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