window.location
works fine, but returns me the whole, absolute path, like http://domain.xyz/punch/lines
. But I only need http://domain.xyz/
I think it will ok for you
var base_url = window.location.origin;
var host = window.location.host;
var pathArray = window.location.pathname.split( '/' );
Try this:
location.protocol + "//" + location.host
You can get the protocol and the host separately, and then join them to get what you need
window.location.protocol + "//" + window.location.host + "/"
As a sidenote, window.location.pathname
would contain the path.
You can use this statement
var baseUrl = document.location.origin;