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


How Lack of Rest Can Impact Your Finances Small Businesses Can Enhance File Management Following these Tips How Much Do Real Estate Agents Spend on Marketing? How to Engage Your Online Audience for Long-Lasting Success Why is Plagiarism Such a Big Deal? Resume Service Review: Why Everyone Should Use It