Recently, we have a strange issue. The list was not showing ribbon tabs default. There are many reasons I found for this behavior, like
- Permission issue - we have site collection access
- custom script to stop ribbon load - we have checked there was no custom coding done.
Then we found a blog stating that even if you add any custom webpart in list / library page, the ribbon lost its focus from main webpart. So it won't show. Andd it was true. we have added a legal text in our list heading using content editor webpart.
Solution:
So what is solution to bring it back? Below is code sample that we added in our page for loading ribbon tab on page load.
Code:
window.onload = function(){
var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
if (elem != null) {
var dummyevent = new Array();
dummyevent["target"] = elem;
dummyevent["srcElement"] = elem;
elem.parentNode.click();
WpClick(dummyevent);
}
//code to click browse button
document.getElementsByClassName("ms-cui-tt-span")[0].click();
}