2

i will get SharePoint Tenent Site URl using Javascript...

below My Site URL:- https://pp1.sharepoint.com/sites/Test/Poject/

I have get only Tenent Site URL:-

https://pp1.sharepoint.com/

2 Answers 2

3

You can use the below code:

var tenantUri = window.location.protocol + "//" + window.location.host;
//you can replace window.location.protocol with https: as in case of SPO it will always be https 
console.log(tenantUri)

This will give you the tenant url irrespective of your path.

1

code to get root site collection url:

string rootSiteCollectionURL = SPContext.Current.Web.Site.WebApplication.Sites[0].Url;

// site collection url

string SiteCollectionURL = SPContext.Current.Web.Site.Url;

Using JavaScript:

window.location.origin

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.