In Javascript, how do I “clear” the back (history -1)?

前端 未结 3 519
忘掉有多难
忘掉有多难 2020-11-29 22:26

When the user loads the page, I immediately do a window redirect to another location.

The problem is, when the user clicks back, it\'ll go back to the page which doe

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 22:51

    Instead of using window.location = url; to redirect,

    try:

    window.location.replace(url);
    

    after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.

提交回复
热议问题