Header Ads

List of JavaScript Location Object

What is use of Location Object?
The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.
1. href => This will return the entire URL displaying in the address bar.
var currentURL = window.location.href;

2. hostname => This will return only the hostname of the URL in address bar.
var currentHostname = window.location.hostname;

3. host => This will return the hostname and port of the URL in address bar.
var currentHost = window.location.host;

4. pathname => This will return the pathname (value after the domain name) of the URL in address bar.
var currentPathname = window.location.pathname;

5. port => This will return only the port detail of the URL in address bar.
var currentPort = window.location.port;

6. hash => This will return the anchor portion of the URL including hash sign (#).
var currenthash = window.location.hash;

7. search=> This will return the query portion of the URL like portion started with the question mark (?)
var currentSearchString = window.location.search;

8. protocol => This will return the protocol of the URL in address bar. Like the URL is using HTTP (without SSL) or HTTPS (with SSL).
var currentProtocol = window.location.protocol;

No comments:

Powered by Blogger.