0

I am trying to concat two strings using urlCombine method like this:

SP.Utilities.UrlBuilder.urlCombine(_spPageContextInfo.webAbsoluteUrl, AnotherUrl);

The AnotherUrl might contain a slash / and when it does, the result url will be like:

http://sitename/sites/myweb//anotherurl 

So basically the urlCombine didn't work. Why is that? I still have duplicate urls.

0

What do you mean by 'It didn't work'? It's doing exactly what it is supposed to do.

Here is the function definition:

SP.Utilities.UrlBuilder.urlCombine = function SP_Utilities_UrlBuilder$urlCombine(path1, path2) {
    if (path1.endsWith('/')) {
        return path1 + path2;
    }
    else {
        return path1 + '/' + path2;
    }
};

As you can see, the function handles two cases.

1) The first path ends with '/'

  • In this case all the function does is to concatenate both parts

2) The first path does not end with '/'

  • In this case all the function does is to concatenate both parts with a '/' between them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.