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

Closed

$().SPServices.SPGetCurrentSite Documentation

description

From: https://spservices.codeplex.com/discussions/551159

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.

Thanks,

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

comments

sympmarc wrote Oct 16, 2014 at 2:14 PM

Fixed in 2014.02ALPHA5

sympmarc wrote Oct 16, 2014 at 2:17 PM

Fix:
    // Get the current context (as much as we can) on startup
    // See: http://johnliu.net/blog/2012/2/3/sharepoint-javascript-current-page-context-info.html
    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.host + (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