You are on page 1of 3

Location Object

This is used to access the current location (URL) of the window. The Location
object can be both read and replaced, so it is possible to update the location of
a page through scripting. Location object is a property of Window.
Syntax:-
window.location.property
window.location.method
Properties
• hash – The part of the URL including and following the # symbol.
• host – The hostname and port number.
• hostname – hostname
• href – entire URL
• pathname – Path relative to the host.
• port – Port Number
• protocol – Protocol of URL
• search – The part of the URL including and after the ?
Methods
• assign(URL) – It changes the location of current page with the passed in URL.
• reload( ) – Reload the current page.
• replace (URL) – Replaces the current page with the given URL in history. As it is
replaced in history, it won’t be possible to access the current page with
back/forward.

You might also like