Difference between window.location.replace(...) and window.location.href

Ashish Kasama
1 min readFeb 3, 2022

There are several time when we get confused on multiple way for performing one action.

Simple example is redirecting/navigating to other page.

  1. use function called window.location.replace()
  2. use properties called location.href

window.location.replace()

This function will not save the current page in session history, so when you click on the back button, It will not have previous page url. It is more useful when you are looking for redirection instead of navigation

window.location.replace(‘https://www.lucentinnovation.com');

window.location.href

This attribute will save the current page in session history, so when you click on the back button, It will pop previous page url. It is more useful when you are looking for navigations.

window.location.href= ‘https://www.lucentinnovation.com';

--

--

Ashish Kasama
Ashish Kasama

Written by Ashish Kasama

Founder and CTO, I am responsible for implementing client thoughts into digital world, bring latest technology in day to day work

No responses yet