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

前端 未结 3 516
忘掉有多难
忘掉有多难 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:52

    You can use location.replace to replace the current location entry (the redirect page) with the new one (the target). That requires that you do the redirection via JavaScript rather than with meta tags or a 302. E.g.:

    // In the redirecting page
    location.replace("path/to/target/page");
    

    Live example | Live example source

提交回复
热议问题