How to get the current URL in JavaScript

JavaScript is used to open the browser and get the URL. You can also rely on JavaScript’s  location  property on the  window  object.


 window  is the global object of the browser. The property can be referenced by


This is a Location object that has many properties of its own.

The URL of the current page is visible in


You may also find useful information from other properties:

Code Description
location.hostname the host name
location.origin the origin
location.hash the hash, the part that follow the hash # symbol
location.pathname the path
location.port the port
location.protocol the protocol the query string


Exit mobile version