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:
by
location.href
property - Current domain name:
by
location.hostname
property - Current path name:
by
location.pathname
property - Current port:
by
location.port
property - Current protocol:
by
location.protocol
property
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;