Thursday, October 22, 2009

Adding External Javascript files into SharePoint



WSS 3.0 keeps all of it's external script files in 12/Templates/Layouts/1033. This localized managed path hosts common file such as"core.js" and other external resources. It's becoming a common task to include custom JavaScript in SharePoint pages that is registered. One of the "nifty" controls that WSS 3.0 offers is the SharePoint ScriptLink control (< SharePoint:Link />), this control allows a developer to link to external script file living in the localized managed path. Here's a practical example that should shed some light on the subject:

1.) Include the following in an external javascript file named "Superman.js".


document.write("I am the night.");


2.) Copy "Superman.js" to 12/Templates/Layouts/1033.

3.) Now add the following control to the head of your masterpage:

< SharePoint:Link ID="Batman" language="javascript" name="Superman.js" />


That's it! Just upload the masterpage into the masterpages gallery and you should see "I am the night" printed on your pages every time they load. This control will become very useful when you begin to use new technologies like "Silverlight" or integrating the "oh so holy" Flash into SharePoint. 

Enjoy! :)

No comments:

Post a Comment