Javascript/jQuery get root url of website

Here's a function doing the same as Hawk's post above, only much, much shorter:

function getBaseUrl() {
    var re = new RegExp(/^.*\//);
    return re.exec(window.location.href);
}

Details here: Javascript: Get base URL or root URL


slightly shorter:

function getBaseUrl() {
    return window.location.href.match(/^.*\//);
}

Use the following javascript to get the root of your url:

window.location.origin

For more details:

 [https://www.codegrepper.com/code-examples/javascript/javascript+get+root+url][1]