SharePoint 2013 add javascript after whole page load

前端 未结 5 887
死守一世寂寞
死守一世寂寞 2020-12-12 20:06

Disclaimer: I have no experience with SharePoint2013.

I have problem - I must include/fire some javascript functions after the whole page has been loaded. I tried li

5条回答
  •  心在旅途
    2020-12-12 20:55

    You are right, MANY things happen on page after $(document).ready(). 2013 does provide a few options.

    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:

    executeFunc: http://msdn.microsoft.com/en-us/library/ff409592(v=office.14).aspx

    ExecuteOrDelayUntilScriptLoaded: http://msdn.microsoft.com/en-us/library/ff411788(v=office.14).aspx

    Cant find a source on _spBodyOnLoadFunctionNames but I am using it in a few places.

    good luck.

提交回复
热议问题