BOW
Testing browser object model
by Eugen Sunic
HTML
<p id="full-url"> </p>
<p> </p>
<p> </p>
<p class="some"> </p>
<p class="some"> </p>
<p id="port"> </p>
JavaScript
// return full url
document.querySelector('#full-url').textContent = window.location.href;
// return host-domain only
document.getElementsByTagName('p')[1].innerText = window.location.host;
// return protocol-value only
document.querySelectorAll('p')[2].innerText=window.location.href.substring(0,window.location.href.indexOf(':')+1);
//OR
document.getElementsByClassName('some')[0].textContent=location.protocol;
// returns the pathname of the current page.
document.getElementsByClassName('some')[1].textContent=location.pathname;
// return port number
document.getElementById('port').innerHTML=window.location.port;
// load a new url;
window.location.assign("https://www.w3schools.com");