Frage

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

War es hilfreich?

Lösung

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!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top