The DOM Location Object Properties
(Page 1 of 6 )
In this article we will cover the DOM Location Objects, which are used to set or return information regarding a user’s URL. Often considered an HTML DOM object, it is really more of a JavaScript object, created by the runtime engine. Like other objects, it consists of both Properties and Methods, the former of which we will be discussing today.
There are eight Location Object properties in total and we will try to cover them as best we can here. They are the hash, host, hostname, href, pathname, port, protocol, and search, respectively. Below is a table showing what each one is used for:
Name | What It Does | Type |
hash | Used to set or retrieve the URL starting from the hash (#) symbol. | Property |
host | Used when you want to set or retrieve the port number and hostname of the URL. | Property |
hostname | Used to set or retrieve the hostname of the present URL. | Property |
href | Used to retrieve or set the entire URL. | Property |
pathname | Used to retrieve or set the pathname of the present URL. | Property |
port | Used to retrieve or set the port number of the present URL. | Property |
protocol | Used to retrieve or set the protocol of the present URL. | Property |
search | Used to retrieve or set the URL from the question (?) mark. | Property |
Next: Hash It Up >>
More JavaScript Articles
More By James Payne