href property of the current webpage into another where the new URL or Webpage will be loaded. The second one is using the
replace() function in order to replace the current web page with another web page or URL.
Redirect with “window.location.href” Property
Every webpage provides the
location attribute which is used to set and get the location-related configuration. The
href attribute is used to get and set the webpage or URL. We will use
window.location.href in order to redirect the current webpage into another webpage or URL.
The “window.location.href” simulates a mouse click like clicking an anchor or href in HTML. So when the page redirection is completed the previous original page is stored in the history and it can be navigated with
Back button of the web browser.
window is a global object and we can directly access the
location.href attribute like below without using the window.
Redirect with “window.location.replace()” Function
Another way to redirect a webpage is using the
Redirect with jQuery
$(location).attr or $(window).attr and
$(location).attr('href','https://www.wisetut.com') $(window).attr('location','https://www.wisetut.com') $(location).prop('href', 'https://www.wisetut.com')