2 回答
TA贡献1798条经验 获得超7个赞
您可以尝试修改历史记录,并使用状态来了解用户是否返回
window.onpopstate = function(event) {
if (event.state && event.state.redirect) {
window.location.replace("http://www.google.com");
}
};
history.replaceState({redirect: true}, "");
history.pushState({redirect: false}, "");
TA贡献1884条经验 获得超4个赞
有一个错误window.location.href('https://google.co.in')只是用window.location.href = 'https://google.co.in';它替换 它会起作用。location.href 在给定链接的情况下像这样使用,下面给出了另一种方法。
window.location.replace("http://www.google.com");该事件触发的beforeunload功能:
直接在浏览器中或通过链接导航到另一个页面。
关闭当前浏览器窗口或标签页。
重新加载当前页面。
通过 JavaScript 中的 location 对象操作当前加载页面的 URL。
调用 window.navigate 方法。
调用 window.open 或 document.open 方法在同一窗口中打开文档。
此代码阻止后退按钮并将窗口替换为 google.com
window.addEventListener( "pageshow", function ( event ) {
var historyTraversal = event.persisted ||
( typeof window.performance != "undefined" &&
window.performance.navigation.type === 2 );
if ( historyTraversal ) {
// Handle page restore.
window.location.replace("http://www.google.com");
}
});
添加回答
举报
