SharePoint 2013 add javascript after whole page load

前端 未结 5 889
死守一世寂寞
死守一世寂寞 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 21:09

    There are different techniques used to provided our custom JavaScript code loaded before / in the middle / after OnLoad events in SharePoint:

    ExecuteOrDelayUntilBodyLoaded.
    Sys.Application.pageLoad.
    document.ready Jquery.
    _spBodyOnLoadFunctionNames.
    _spBodyOnLoadFunction.
    ExecuteOrDelayUntilScriptLoaded:sp.core.js.
    SP.SOD.executeFunc: sp.js.
    Sys.WebForms.PageRequestManager.PageLoaded
    

    – ExecuteOrDelayUntilBodyLoaded function is always executed the first (but at this stage we can not access to SP methods). This could be usefull to execute our custom code at really earlier stage in the OnLoad process.

    – There are two SharePoint onLoad functions _spBodyOnLoadFunctionNames and _spBodyOnLoadFunction. Always executed in the order. SO, if we want to execute some code after all functions included by us (or other devs) in _spBodyOnLoadFunctionNames, then is useful to use this one _spBodyOnLoadFunction, because is executed the last.

    – ExecuteOrDelayUntilScriptLoaded:sp.core.js and SP.SOD.executeFunc: sp.js. are swapping the order of execution in a random way.

    – If we want to execute some functions after all functions (SP, after load functions, Yammer, etc.) we can use this function to attach the OnLoad event –> Sys.WebForms.PageRequestManager.PageLoaded.

    You can see the whole article explaining each type, pros and cons here: https://blog.josequinto.com/2015/06/16/custom-javascript-function-loaded-after-the-ui-has-loaded-in-sharepoint-2013/

    Regards!

提交回复
热议问题