Tallan's Blog

Tallan’s Experts Share Their Knowledge on Technology, Trends and Solutions to Business Challenges

Posts Tagged "scripts on demand"

Use SP.SOD.executeFunc(a,b,c) to load the SharePoint JavaScript libraries when needed

Patrick Kelly

A couple weeks ago, I was building a stock quote for a master page that required two images stored in /Style Library/Custom/; the images represented the typical stock quote arrows. In order to provide the JavaScript code with the correct location of the site collection’s root I was using the following directly in my code block:

var imgArrow = <asp:Literal runat=”server” Text=”<%$SPUrl:~sitecollection/

Style Library/Custom/images/stockup.png%>” />;

While I had originally thought this was a kludgey solution to begin with, it was getting the job done every single time.
However, a problem arose a few days after when I began refactoring the code. I had moved all of the js code from the master page itself into a separate js file, leaving only a static reference to the script on the master. The following code should be put within the ScriptManager control.

<asp:ScriptReference…

\\\