While working on client side scripting, you can generate urls as follows: Site Collection window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl; Sub Site _spPageContextInfo.webAbsoluteUrl; QED
Cloud development @ its best. Snippets, ideas, latest, best practices etc.