Question

Basically I have the same question as this one with allmost the same goal. I have a SP2016 on premise and I want to modify the suitebar by java script. I have allready tried the answer of the question above!

I have linked jquery and custom js-file at the bottom of the master-file:

<!-- Referencing jQuery and custom js-files -->
<SharePoint:ScriptLink language="javascript" name="~sitecollection/SiteAssets/SP2016/jquery.js" 
LoadAfterUI="true" OnDemand="false" runat="server" Localizable="false" />
<SharePoint:ScriptLink language="javascript" name="~sitecollection/SiteAssets/SP2016/sp2016.js" 
LoadAfterUI="true" OnDemand="false" runat="server" Localizable="false" />

<SharePoint:ScriptBlock runat="server">
    $_global_skb_sp2016_js();
</SharePoint:ScriptBlock>

In my JS file I have this

var $jq = jQuery.noConflict();

function $_global_sp2016_js() {

    Function.registerNamespace('sp2016');

    window.setTimeout(function() {
        EnsureScriptFunc('sp.js', 'SP.ClientContext', sp2016.suitebar);
    }, 5000);

    console.log("I bins: _global_skb_sp2016_js_func1 ;-)");

    sp2016.suitebar = function() {
        console.log("suitebar: " + Date.now());
        // ... modify suitebar
    };
};
$_global_skb_sp2016_js();

If I load this website the first time (or with "Strg"+"F5") this code works (it is called twice - but this would be no problem for me). But if I use a (internal) link on this website this code is not run and the suitebar is reseted to default!

What am I doing wrong here? Is there any other possibility (in SP2016) to add a second link the SuiteNavBrandingText?

Was it helpful?

Solution

Use the asyncDeltaManager to support MDS. Include this code on page load to also call your method on delta loads:

if (typeof asyncDeltaManager != "undefined") {
    asyncDeltaManager.add_endRequest($_global_sp2016_js);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top