Window.location.href
window.location.href returns current web page browser url. URL contains all parts of url which means protocol, hostname, port and pathname.
Example
http://www.google.com:8054/mail
http - protocol
www.google.com - hostname
8054 - port
/mail - pathname
|
Window.location.protocol
window.location.protocol returns http or https protocol of the current web page request in javascript.
|
Window.location.hostname
window.location.hostname returns current web page browser hostname of the url.
|
Window.location.port
window.location.port returns port number of the url if it is not exist so returns empty.
|
Window.location.pathname
window.location.pathname returns current web page URI.
|
document.write("URL: "+window.location.href);
document.write("<br />");
document.write("PROTOCOL: "+window.location.protocol);
document.write("<br />");
document.write("HOST NAME: "+window.location.hostname);
document.write("<br />");
document.write("PORT: "+window.location.port);
document.write("<br />");
document.write("WEB PAGE URI: "+window.location.pathname);
document.write("<br />");
|
Demo & Output
|