How get to base URL in JavaScript

2 Answers

0 votes
document.write(location.protocol + "//" + location.host);

/*
run:
 
http://localhost:8080 
   
*/

 



answered Jul 20, 2015 by avibootz
0 votes
document.write(window.location.protocol + "//" + window.location.host + "/");

/*
run:
 
http://localhost:8080/ 
   
*/

 



answered Jul 20, 2015 by avibootz
...