Window.location object

Javascript can access the URL of the current page with window.location object. This object contains various properties of the URL such as protocol, host, pathname, search and more.

  • window.location.href returns the href (URL) of the current page
  • window.location.hostname returns the domain name of the web host
  • window.location.pathname returns the path and filename of the current page
  • window.location.protocol returns the web protocol used (http: or https:)
  • window.location.assign() loads a new document
<button class="newDocument">
   New Document
console.log(window.location.href); //""

console.log(window.location.hostname); //""

console.log(window.location.pathname); //"/_display/"

console.log(window.location.protocol); //"https:"

//Window.location.assign - click on the "New Document" button to load a new document.

function newDocument() {

const newDocButton = document.querySelector(".newDocument");

newDocButton.addEventListener('click', newDocument);