I need to get the the site colllection url using the javascript. I have written one simple function as below
function getSiteCollectionUrl()
{
var pageUrl= window.location.href;
var protocol = pageUrl.split(":")[0];
var addr=pageUrl.split("//")[1];
var webUrl = addr.split("/")[0];
var siteColleUrl = protocol + "://" + webUrl
}
let say the site address is "http://mysite/trialsite/default.aspx", then it will return: "http://mysite" But I think this isn't proper way to get the site collection url.
PLease suggest if you have any other idea.