Get current url port, hostname and path in JavaScript

window.location is an Object with properties of current location namely

window.location.href returns the href url of the current page

window.location.hostname returns the domain name

window.location.pathname returns the pathname segment of the url

window.location.protocol returns the web protocol of the url

window.location.assign() loads a new document


Popular posts from this blog

What is 'this.' keyword in JavaScript

How to create promises in JavaScript

How to make a static http server in nodejs using express

How to make a Snake Game using JavaScript and html5

How to get user's ip address in JavaScript