javascript how to construct base url for localhost code example Example: js get base url var url = window.location.origin;