window.location= “xxx.html”;(orwindow.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.
本文详细解释了如何使用JavaScript中的window.location、window.location.href和window.location.replace方法来模拟用户点击链接和实现HTTP重定向。重点讨论了replace()方法的优势,因为它不会将原始页面添加到会话历史中,避免了无限回退按钮问题。
1025

被折叠的 条评论
为什么被折叠?



