如何解决浏览器后退按钮重定向脚本
我正在尝试开发“浏览器后退按钮”重定向脚本。
因此,基本上,当用户到达Google或其他任何社交媒体的index.html时,单击后退按钮时,用户应转到指定的页面。
我尝试使用javascript创建它,但无法正常工作。有人可以帮忙吗?
我创建了3个页面
1)Index.html
<!DOCTYPE html>
<html>
<body>
<p><a href="redirect.html">Redirect Page</a></p>
</body>
</html>
2)redirect.html
<!DOCTYPE html>
<html>
<head>
<script>
function init() {
setTimeout(function(){window.scrollTo(0,1)},0);
}
window.history.pushState(‘back.html’,‘back’,‘back.html’);
window.history.pushState(‘index.html’,‘Index’,‘index.html’);
window.addEventListener(“popstate”,function(e) {
if(document.URL.indexOf(“back.html”) >= 0){
document.location.href = document.location;
}
});
</script>
</head>
<body>
<p>By pressing the browser back button it should redirect to specified url</p>
</body>
</html>
3)back.html
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<script>
document.location.href = “https://www.google.com”;
</script>
</head>
<body>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。