SyntaxFix
Write A Post
Hire A Developer
Questions
Try:
document.location.protocol + '//' + document.location.host + document.location.pathname;
(NB: .host rather than .hostname so that the port gets included too, if necessary)
.host
.hostname