2017-02-15

JavaScript provides you many methods to get the current URL displaying in web browser address bar. You can use Location object property of the Window object to get these details. Below is the list of few properties of location object. The first example will get current URL in web browser. Some more examples are also listed below for your reference.

1. href => This will return the entire URL displaying in the address bar.

2. host => This will return the hostname and port of the URL in address bar.

3. hostname => This will return only the hostname of the URL in address bar.

4. post => This will return only the port detail of the URL in address bar.

5. protocol => This will return the protocol of the URL in 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 address bar.

7. pathname => This will return the anchor portion of the URL including hash singh (#).

8. search=> This will return the query portion of the URL like portion started with the question mark (?).

The post How to Get Current URL in Web Browser using JavaScript appeared first on TecAdmin.net.

Show more