How to Get the Current URL Using Javascript?
To get the current URL using JavaScript, you can use the window.location.href property.
Here is an example code:
var currentURL = window.location.href;
console.log(currentURL);
In this example, the variable currentURL contains the current URL of the page, and the console.log statement logs this URL in the browser console for debugging purposes.
You can also use other properties of the window.location object, such as window.location.protocol, window.location.host, and window.location.pathname, to get specific parts of the current URL.
For example, to get the domain name of the current URL, you can use window.location.host:
var domainName = window.location.host;
console.log(domainName);
This will log the domain name of the current URL to the console.