What is the purpose of using the window.location.href?

“window.location.href is a JavaScript property that is used to retrieve or set the URL of the current webpage.”

Usage is as follows:

Grab the current page’s URL:
var currentURL = window.location.href;

To set the URL of the current page, use:
window.location.href = “https://www.example.com”;
By setting the window.location.href property, you can redirect the page, similar to clicking on a link or entering a website address for redirection.

bannerAds