Location object
Location object contains information about the current URL. location object is part of the window object, you can access the window.location property.
Note: There is no suitable location object's public standards, but all major browsers support it.
<! DOCTYPE HTML > < HTML > < Meta charset = "UTF-8" > < title > JS </ title > < body > < the p- > Click this button to display the entire URL of the current page. </ P > < Button οnclick = "myFunction ()" > try </ Button > < P ID = "Demo" > </ P > < Script > = location.href; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
Location object properties
You can use the following properties in the Location object:
Attributes | description |
---|---|
hash | Sets or returns the anchor part of the URL (#) |
host | Sets or returns the host name and port number of the URL |
hostname | Sets or returns the host name of the URL |
href | Sets or returns the entire URL |
origin | Returns the URL protocol, host name and port number |
pathname | Sets or returns the URL path name |
port | Sets or returns the port number of the URL |
protocol | Sets or returns the URL protocol |
search | Sets or returns the URL query string section |
Location object methods
The following methods may be used in the Location object: