2

In my SharePoint site first I want to get Host URL(/Site URL ),and user would enter Relative URL in TextBox. Then I want to append that relative URL with Host URL Using jquery and need to check that URL before submit action.

How to get Relative URL using jquery in SharePoint Site?

9

Use _spPageContextInfo in your JavaScript.

Usage:

var url = _spPageContextInfo.webServerRelativeUrl;
alert(url);

See others here:

http://blah.winsmarts.com/2013-2-_sppagecontextinfo_is_your_new_best_friend.aspx

1

For Relative Path in sharepoint you can use any of the two:

var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;

Or we can use

var context = new SP.ClientContext();
var relativeWebUrl = context.get_url();
var fullWebUrl = window.location.protocol + '//' + window.location.host + relativeWebUrl ;
0

JSRequest.EnsureSetup();

JSRequest.PathName: returns the relative path.

JSRequest has a few other helpful methods also. See below.

http://social.technet.microsoft.com/wiki/contents/articles/20820.sharepoint-2010-about-jsrequest.aspx

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.