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>
<p id="navigator1"> </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, fires immediately
//window.location.assign("www.google.com");

// simulate browser back button
//window.history.back()

// simulate browser forward button
//window.history.forward()

// contains information about the visitor's browser
window.navigator.appName

document.querySelector("#nagivator1").innerText=window.navigator.appName