Thursday, November 20, 2008

Javascrip in SharePoint

To refer Javascript file in Sharepoint 2007,

1) Go to "1033" folder in Layouts folder( c:\program files\common files\microsoft shared\web server extensions\12\template\Layouts\1033). This is the default folder that Sharepoint 2007 refers for Javascript files.


2) Add your custom javascript file in the folder ( for example, StockTicker.js file to refresh the control, with code as
var intervalID;
intervalID = window.setInterval("refreshStockTicker()",3000);
function refreshStockTicker() {document.execCommand("Refresh");};

3) To refer that javascript file in SharePoint, go to the sharepoint page using SharePoint Designer. And, refer it with the "SharePoint:ScriptLink" and "Name" as Javascript file name like,


if (!StockTicker1.IsClientScriptBlockRegistered("refreshCode"))
{ StockTicker1.RegisterClientScriptBlock("refreshCode", code); }


In above, StockTicker1 is the name of the control to be refreshed for every 3 seconds.

No comments: