
Notes:The window.location object can be written without the window prefix.For example, we try to get current page information:
- URL of current page:
bylocation.hrefproperty - Current domain name:
bylocation.hostnameproperty - Current path name:
bylocation.pathnameproperty - Current port:
bylocation.portproperty - Current protocol:
bylocation.protocolproperty
HTML source:
<code class="code" id="current_url"></code> <code id="current_domain"></code> <code id="current_path"></code> <code id="current_port"></code> <code id="current_protocol"></code>Javascript source:
document.getElementById('current_url').innerHTML= window.location.href;
document.getElementById('current_domain').innerHTML= window.location.hostname;
document.getElementById('current_path').innerHTML= window.location.pathname;
document.getElementById('current_port').innerHTML= window.location.port;
document.getElementById('current_protocol').innerHTML= window.location.protocol;