1
  1. I want to get ServerRelativeUrl property on SharePoint page using JavaScript without loading SP.JS file. Is there any way to get this.

E.g. URL: https://example.domain.com/sites/sample/pages/home.aspx I want "/sites/sample" as my Server Relative Url

  1. If above does not works then can I get Server Relative Url using only JavaScript code i.e. without using SharePoint refrence, something like window.location

Thanks in advance!

2
  • Please refer this link from TechNet. This will work for you - social.technet.microsoft.com/wiki/contents/articles/… Commented Mar 9, 2016 at 14:24
  • You can inspect the debug versions of SP.JS and recreate the object yourself, but I really have to wonder why you can't just use SP.JS. Commented Mar 9, 2016 at 14:50

3 Answers 3

2

You can use _spPageContextInfo.siteServerRelativeUrl to get the server relative url as same as '/sites/sample'

0
0

I can use _spPageContextInfo.webAbsoluteUrl to get server relative url of current web or _spPageContextInfo.siteAbsoluteUrl to get that or current site.

0

As mentioned by Gert, use the below JavaScript snippet to get the server relative URL

    <script type="text/javascript">
    var serverRelativeUrl = _spPageContextInfo.siteServerRelativeUrl;
    alert(serverRelativeUrl);
    </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.