DeepDive to Browser object Model

Location object:

  • The Location interface represents the location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Both the Document and Window interface have such a linked Location, accessible via Document.location and Window.location respectively.     

  • 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 .
>>> console.dir(location)
VM140:1


Location
ancestorOrigins: DOMStringList {length: 0}
assign: ƒ assign()
hash: ""
host: "coderdnes.github.io"
hostname: "coderdnes.github.io"
href: "https://coderdnes.github.io/StoreAppLocator/"
origin: "https://coderdnes.github.io"
pathname: "/StoreAppLocator/"
port: ""
protocol: "https:"
reload: ƒ reload()
replace: ƒ replace()
search: ""
toString: ƒ toString()
valueOf: ƒ valueOf()
Symbol(Symbol.toPrimitive): undefined
__proto__: Location

  • 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       


console.dir(history)
VM172:1
  1. History
    1. length2
    2. scrollRestoration"auto"
    3. statenull
    4. __proto__History
      1. length(...)
      2. pushStateƒ pushState()
        1. arguments(...)
        2. caller(...)
        3. length2
        4.  :name"pushState"
      3. scrollRestoration(...)
      4. state(...)
      5. Symbol(Symbol.toStringTag)"History"

     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

Popular posts from this blog

JavaScript — Double Equals vs. Triple Equals - weird things on JavaScript

06_Understanding Execution Context and Execution Stack in Javascript

Creating and inserting element- part-2