3

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?

Vii
  • 43
  • 4

1 Answers1

2

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);
}
Lars Fastrup
  • 3,150
  • 2
  • 22
  • 29
  • That works! Thank you! Where did you get this info? I've been googling tons of sites and blogs, I had more than one sharepoint course but every info I really need in every day business I only get from "sharepoint pro's" and/or our sharepoint consultant?! – Vii Aug 17 '17 at 07:52
  • Forgot where I learned it. Have been using it in several SharePoint apps for a couple of years. But I have probably been searching for SharePoint, JavaScript and MDS. – Lars Fastrup Aug 17 '17 at 08:42