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!


3 Answers 3


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


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


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

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

Your Answer

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

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