Window Location Href Property
The window.location.href property of window.location object will return the current web page URL. We are going to see an example.
Our current page URL will be shown in p tag which has an ID that you can see below:
In the above code, we have put the current page URL in a variable “currentURL”. After that, we have we select our paragraph tag by its ID and set the HTML content with innerHTML property. In our HTML content, we pass the variable that contains the current page URL.
Now we can run our code.
Let’s try it yourself, run the code on your browser. If you run the code, you will be able to see the current page URL on the web page.