Useful Javascript Functions and objects in SharePoint – Part 1

SharePoint has a huge set of javascript functions and objects which are defined in essential SharePoint javascript files like init.js, core.js, forms.js etc. These files are necessary for SharePoint to function properly. There is no reason to reinvent the wheel by writing your own javascript function for something which is already provided by these core javascript files.
I will run a series of articles to list down necessary objects and functions provided by SharePoint. I hope you will find them useful.

Useful Objects

JSRequest : It is a global object which is used to get information about current page. It has following properties:

  1. QueryString : An array of Querystring key and values,
  2. FileName : Name of the current file e.g. default.aspx
  3. PathName : current path of the page

NOTE: Before using this object properties, always call JSRequest.Ensuresetup()

L_Menu_BaseUrl : Relative path for current site. e.g.  “/TestSite”. It is useful to construct web relative paths for ajax calls of web services etc.

L_Menu_LCID : Current culture Id e.g.  “1033” for US English.  It is useful to retrieve culture specific files, if need.

L_Menu_SiteTheme : Current site theme name e.g. Lacquer. If no theme is applied then it will be empty.

browseris : This object has several properties to detect browser name, major and minor version, operating system version etc. For example, if you want to know whether the current browser is IE or not then check If it is true then IE else others. To get full details of its properties, use FireBug.

LegalUrlChars : Array of all characters which are allowed in Url for SharePoint.

_spBodyOnLoadFunctionNames : Array of javascript function names to be executed just after DOM is fully loaded. If you want to execute any of your function once the page is fully loaded then add your function name in this array. For example _spBodyOnLoadFunctionNames.push(“MyFunction”);

_spUserId : User Id of the currently logged in user. It is an integer e.g. 1. You can use this value perform any logic against a currently logged in user.

ctx or ctx1 or ctx2 … etc. There can be many ctx objects in a single page. These objects are instances of ContextInfo class. They are used to provide user context information necessary to create Edit Control Block menu items. Please use FireBug to see the list of all properties available. Visit here for more info

g_ExtensionDefaultForRead : An array of file extension strings which are always checked out as Read only. For example, jpg, jpeg, bmp etc.

g_ExtensionNotSupportCheckoutToLocal : An array of file extension strings which are not allowed to checkout locally. For example, aspx, ascx, cmd etc.

Check my next post for available Javascript functions.