This project has moved. For the latest updates, please go here.


$().SPServices.SPGetCurrentSite Documentation



Marc, In the "SPGetCurrentSite" function's documentation, it states the function will return the complete site URL.

I noticed in the lated release (2014.01), the "SPGetCurrentSite" function returns the string from "currentContext.thisSite" (if available). That result is a relative URL, stripping the protocol and domain from the front end. i.e., returns "/sites/path/subpath" instead of "https://mydomain/sites/path/subpath" (at least it does so in IE and SP 2007). It's not a huge deal unless the user's code is doing a full text comparison of that string and is expecting the full URL (as was my case in a particular instance--which is how I discovered this).

I noticed the code will defer to a web service call (WebUrlFromPageUrl) to get the URL if "currentContext.thisSite" isn't available. The web service returns the complete site URL. So, in this function, the two methods will return the string to the user differently depending on the method the function uses. That may cause some confusion in the long run.


Closed Dec 16, 2014 at 5:34 PM by sympmarc
Fixed/deployed in 2014.02


sympmarc wrote Oct 16, 2014 at 1:14 PM

Fixed in 2014.02ALPHA5

sympmarc wrote Oct 16, 2014 at 1:17 PM

    // Get the current context (as much as we can) on startup
    // See:
    function SPServicesContext() {

        // The SharePoint variables only give us a relative path. to match the result from WebUrlFromPageUrl, we need to add the protocol, host, and (if present) port.
        var siteRoot = location.protocol + "//" + + (location.port !== "" ? location.port : "");

        // SharePoint 2010 gives us a context variable
        if (typeof _spPageContextInfo !== "undefined") {
            this.thisSite = siteRoot + _spPageContextInfo.webServerRelativeUrl;
            this.thisList = _spPageContextInfo.pageListId;
            this.thisUserId = _spPageContextInfo.userId;
            // In SharePoint 2007, we know the UserID only
        } else {
            this.thisSite = (typeof L_Menu_BaseUrl !== "undefined") ? siteRoot + L_Menu_BaseUrl : "";
            this.thisList = "";
            this.thisUserId = (typeof _spUserId !== "undefined") ? _spUserId : undefined;

    } // End of function SPServicesContext