Question

I'm trying to figure out how to get a portion of the url in a Master Page in SharePoint 2016 on-prem. For example, I have several site collections that look like this:

http://mainsite.domain.com/sites/test1/... http://mainsite.domain.com/sites/test2/...

In a master page, how do I trim off everything after the .com to end up with a url that looks like this:

http://mainsite.domain.com

Était-ce utile?

La solution

Actually, I don't know why you need to get only the hostname in your master page as well as you don't specify where exactly you will use it.

But as per your request, if you need to just get the hostname, try to use the below JS code

var hostname= window.location.hostname;
console.log(hostname);

I suggest to try it first in the console (F12) to make sure that exactly what you need!

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top