DeepDive to Browser object Model
Location object:
- The
Locationinterface represents the location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Both theDocumentandWindowinterface have such a linkedLocation, accessible viaDocument.locationandWindow.locationrespectively.
- is used to access current location of the window.
- can be both read and replaced.
- So,it is possible to update location through scripting.
"location is property of window object"
syntax:
window.location.property
window.location.method
- the below shows how we can acess property of location object at once .
- Accessing property one at a time
window.location.hash
""
window.location.hash = 'Map'
"Map"
window.location.host
"coderdnes.github.io"
window.location.hostname
"coderdnes.github.io"
console.log(window.location.href)
VM933:1 https://coderdnes.github.io/StoreAppLocator/#Map
console.log(window.location.host)
VM1055:1 coderdnes.github.io
console.log(window.location.hostname)
VM1080:1 coderdnes.github.io
console.log(window.location.path)
VM1192:1
console.log(window.location.pathname)
VM1219:1 /StoreAppLocator/
console.log(window.location.protocol)
VM1271:1 https:
Methods:
assign(): changes location of current page with passed in Url
reload() : reload the current page
replace(): replaces the current page with given Url in the history. As it us replaced it wont be able to access with back and forth
History Object:
- is read-only array of url-string that show where the user has been recently visted.
Syntax:
window.history.property
window.history.method
methods:
back() : it loads the previous url in history list
forward() : it loads the next url in history list
go(): it access the particular item in the history list relative to its current position.
Comments
Post a Comment