Wednesday, November 25, 2015

How to load Javascript file properly

  1. The path may not be resolved correctly (sometimes relative urls seem just not to work correctly in SharePoint context)
  2. When using jQuery in Javascript within e.g. a SharePoint webpart try to use jQuery.noConflict() before using the SP-Services. In most cases I had issues with using $ or jQuery because of the already loaded JQuery within SharePoint.
  3. When using javascript in SharePoint $(document).ready might cause problems because this doesn´t actually mean that all content is loaded. You can try to use _spBodyOnLoadFunctionNames.push("myfunction") instead.
  4. Use ExecuteOrDelayUntilScriptLoaded(temp(), "jquery-1.10.1.min.js");
  5. $.getScript("jquery.SPServices-0.7.2.min.js",[optionalFunction() { }]); OptionalFunction() will execute after jquery in 1st parameter loaded successfully

No comments:

Post a Comment