0

I'm trying to add some JavaScript code to my o365 site which should be called everytime when the site is rendered and all the needed objects are initialized. So far I got to this, but still it doesn't work everytime:

<script type="text/javascript">
function theFunction()
{
if (document.getElementById("suiteBrandingIcon") != undefined)
{
// stuff, needed stuiteBradning icon
}
else
{
    setTimeout(theFunction,200);
}
}
ExecuteAndRegisterBeginEndFunctions("sp.ui.pub.ribbon.js",null,null,theFunction);
</script>

I added this strange ExecuteAndRegisterBeginEndFunctions to render the site also after the Sharepoint ajaxdelta is called. I'm adding this code at the end of the masterpage before the body end tag.

Is there any sharepointOnRender handler or anything similar?

1 Answer 1

2

Here are some options to do that: 1) Script on Demand: (load a js file then execute my code.)

function stuffThatRequiresSP_JS(){
    //your code
}

SP.SOD.executeFunc("sp.js")

2) Delay until loaded (wait for a js file, then run)

function stuffToRunAfterSP_JS(){
    //your code
}

ExecuteOrDelayUntilScriptLoaded(stuffToRunAfterSP_JS, "sp.js")

3) load after other stuff finishes

function runAfterEverythingElse(){
    // your code
}

_spBodyOnLoadFunctionNames.push("runAfterEverythingElse");

Sources:https://stackoverflow.com/questions/16936250/sharepoint-2013-add-javascript-after-whole-page-load

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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