document.location.protocol + '//' + document.location.host code example Example: javascript get base url console.log(window.location.origin);