http://www.example.com/
http://localhost/example
http://www.example.com/sub/example
Podemos usar el siguiente código:
var base_url = window.location.origin;
var host = window.location.host;
var pathArray = window.location.pathname.split( '/' );