Referencing JS files using CustomAction element
来源:互联网 发布:新闻知乎 编辑:程序博客网 时间:2024/06/05 19:56
http://www.spdeveloper.co.in/tipsntricks/pages/referencing-js-files-using-custom-action.aspx
Javascript plays an important role in a SharePoint web application. So, as we customize a SharePoint site, we might across a situation where we need to add our custom JS files to SharePoint pages. There are number of ways to refer a JS file on a SharePoint Page.
Adding a Reference in the Master Page: Add a <script> tag on your master page which points to your custom master page. But in this method, we need to create a custom master page just for referencing the custom JS files.
Using Delegate Control through Feature: We can also add a control in the delegate control section through a feature. But for this we need to create a Server control or a User Control to refer the JS file.
Using ScriptSrc and ScriptBlock of CustomAction: The above two methods are widely used in SharePoint 2007. SharePoint 2010 introduced two new attributes forCustomAction element. Using these attributes we can refer a JS file easily. Below is an sample CustomAction tag which is to be used in the elements.xml file of a feature
<CustomAction ScriptSrc="path of your JS file" Location="ScriptLink" Sequence="100"> </CustomAction>
Using this approach we can add the JS files from _layouts directory, alibrary in a SharePoint site or write the script inline.
Referring JS file from _layouts directory: The below example adds a JS file named 'spdutils.js' from the 1033 folder in _layouts directory
<CustomAction ScriptSrc="1033/spdutils.js" Location="ScriptLink" Sequence="100"> </CustomAction>
Referring JS File from a SharePoint Library: The below example adds a JS file from 'Documents' library (Root Site's library) of the SharePoint site
<CustomAction ScriptSrc="~SiteCollection/Documents/spdutils.js" Location="ScriptLink" Sequence="100"> </CustomAction>
Adding the JS code directly in the feature: This shows how to add the JS code directly in the CustomAction element using SrciptBlock attribute
<CustomAction Location="ScriptLink" ScriptBlock="function JSFX_StartEffects(){JSFX.Fire(200, 100, 100);}var windowOnload=window.onload||function(){};window.onload=function(){JSFX_StartEffects();};" Sequence="103"> </CustomAction>
With the addition of ScriptSrc and ScriptBlock elements in CustomAction element, we can easily refer JS files on a SharePoint site. And as this has to be done through a feature, it is more manageable and easy to control.
- Referencing JS files using CustomAction element
- Referencing an Excel Pivot Table Range using VBA
- Using jar files
- Getting Files Using DownloadManager
- moss customaction
- Deploy custom Css,Js files in SharePoint 2010 using visual studio 2010
- Playing .wav files using C#
- Media files conversion using C#
- Reading Excel files using ODBC
- Including header files using "" vs <>
- 4.2.3.3. Using Option Files
- Using standard library header files
- Using Option Files --MySQL Concept
- Using files from web applications
- 1.2.3 Using Option Files
- Using SSIS to zip files and email the zipped files
- USING FORTRAN90 CODE IN MATLAB MEX-FILES
- Insert XML Files into Databases Using Xml2OleDb
- 《MSComm控件小结》
- 黑马程序员-类的加载
- MyBatis 3 入门
- 我实在是想吐槽一下
- 嵌入式汇编语句学习(《linux内核完全注释》)
- Referencing JS files using CustomAction element
- 本人常用的在线格式美化工具
- linux之ssh服务
- CF——#182div2C
- android NDK 交叉编译
- dump controlfile trace ,恢复控制文件
- C语言文件操作函数大全
- web.xml之context-param,listener,filter,servlet加载顺序及其周边
- AFNetworkingErrorDomain 错误