window.location
= “xxx.html”;(or
window.location.href
= "xxx.html";)
window.location.replace("xxx.html")
the first one
, because replace()
does not put the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking on a link, uselocation.href
. If you want to simulate an HTTP redirect, use location.replace
.