You can get the current domain name using JavaScript with the following methods:
Method 1: Using the window. location Object
const current Domain = window. location. hostname; console.log (current Domain)
This method returns the domain name without the protocol (http/https) or port number.
Method 2: Using the document. domain Property
const current Domain = document. domain;console.log (current Domain)
This method returns the domain name of the current document.
Method 3: Using the window. location. origin Property
const current Domain = window. location. origin; console.log (current Domain)
This method returns the protocol (http/https) and domain name, but not the port number.
Note that these methods might not work as expected if you’re using a framework or library that manipulates the window.location object or document.domain property.
Make sure to test these methods in your specific use case to ensure they work as expected.