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

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

|improve this answer|||||
0

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

|improve this answer|||||
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>
|improve this answer|||||

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.