Here is the list of options available to get URLs and other details using JavaScript. The first example will get the current URL in a web browser. Other examples are also available for your reference.
#1 – href
This will return the entire URL displayed in the address bar.
#2 – host
This will return the hostname and port of the URL in the address bar.
#3 – hostname
This will return only the hostname of the URL in the address bar.
#4 – port
This will return only the port detail of the URL in the address bar.
#5 – protocol
This will return the protocol of the URL in the address bar. Like the URL is using HTTP (without SSL) or HTTPS (with SSL).
#6 – pathname
This will return the pathname (value after the domain name) of the URL in the address bar.
#7 – hash
This will return the anchor portion of the URL including the hash sign (#).
#8 – search
This will return the query portion of the URL-like portion started with the question mark (?).