Convert Relative Url to Absolute Url in SharePoint using Javascript

If you are come around core.js file, you all can see many functions available on that file.Those fuctions are very usefull when we need that in customization, for instance

We have a relative url of the current sharepoint site, I need to convert that relative url to absolute url, there comes a simple method called makeAbsUrl

The core.js file can be found @

<Root Directory>:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS1033

Method syntax:


//Code in core.js
function makeAbsUrl(strUrl)
if (strUrl.length > 0 && “/”==strUrl.substr(0, 1))
return strUrl;

Example 1:


The above function retuns a value http://server/Lists/Allitems.aspx

Example 2:

If we have a subsite, then we can use makeAbsUrl as


L_Menu_BaseUrl returns a absolute path of the site.

L_Menu_BaseUrl = /sites/subsite

Now we have return value as http://server/sites/subsite/Lists/AllItems.aspx

Shantha Kumar
Shantha Kumar
Articles: 280