问题描述
我正在尝试开发“浏览器后退按钮”重定向脚本。
因此,基本上,当用户到达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 (将#修改为@)