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/

1

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.

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