lundi 16 mars 2015

Cannot get ribbon button by Id through Javascript



I've got a delegate control which persists a customAction Tab onto every page of my host web. In the same Delegate control file, I reference a javascript file which I want to use to hide specific buttons from the ribbon depending on what page I'm on.


I cannot figure out why, but when I try and get hold of an element in the ribbon, it just returns null.


For Example:



var button = document.getElementById("HelpRibbon.MySites.Tutorials-Large");


returns null.


Here is my code:



'use strict';
var clientContext;
var siteCollection;
var url;
var urlComponents;
var userActions;
var website;


function sharePointReady() {
var url = document.URL;
urlComponents = spliceUrl(url);

if (urlComponents && urlComponents[1] === 'Policies') {
var button = document.getElementById("HelpRibbon.MySites.Tutorials-Large");
var elementOnPage = document.getElementById("idHomePageNewDocument-WPQ2");
if (button) {
button.style.display = "none";
}
}
}

function spliceUrl(url) {
var vars = [];
var hashes = url.slice(url.indexOf('//') + 2).split('/');
for (var i = 0; i < hashes.length; i++) {
vars.push(hashes[i]);
}
return vars;
}
_spBodyOnLoadFunctionNames.push("sharePointReady");


I have tried to get the element with the id that's given to it in this html attribute:



<a class="ms-cui-ctl-large " id="HelpRibbon.MySites.Tutorials-Large" role="button" aria-describedby="HelpRibbon.MySites.Tutorials_ToolTip" onclick="return false;" href="javascript:;" unselectable="on" mscui:controltype="Button">


I have tried to get elements in non-custom ribbons to no avail.


Anyone have any ideas why?








0 commentaires:

Enregistrer un commentaire