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.hrefreturns the href (URL) of the current pagewindow.location.hostnamereturns the domain name of the web hostwindow.location.pathnamereturns the path and filename of the current pagewindow.location.protocolreturns the web protocol used (http: or https:)window.location.assign()loads a new document
<button class="newDocument">
New Document
</button>console.log(window.location.href); //"https://fiddle.jshell.net/_display/?editor_console=true"
console.log(window.location.hostname); //"fiddle.jshell.net"
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() {
window.location.assign("https://www.collegestash.com/")
}
const newDocButton = document.querySelector(".newDocument");
newDocButton.addEventListener('click', newDocument);