suppose that you have a page with this address: http://sub.domain.com/virtualPath/page.htm. use the following in page code to achieve those results:
window.location.host: you’ll getsub.domain.com:8080orsub.domain.com:80window.location.hostname: you’ll getsub.domain.comwindow.location.protocol: you’ll gethttp:window.location.port: you’ll get8080or80window.location.pathname: you’ll get/virtualPathwindow.location.origin: you’ll gethttp://sub.domain.com*****
Update: about the .origin
***** As the ref states, browser compatibility for window.location.origin is not clear. I’ve checked it in chrome and it returned http://sub.domain.com:port if the port is anything but 80, and http://sub.domain.com if the port is 80.
Special thanks to @torazaburo for mentioning that to me.