主动触发window.location.href后无法返回上一页

新手上路,请多包涵

页面A主动发起window.location.href到一个第三方页面,然后在第三方页面点击浏览器原生后退按钮,页面无法正确返回页面A,而是返回到页面A上一个页面。

相关代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
<script>
    window.location.href="https://baidu.com";
</script>
</html>

你期待的结果是什么?

从A页面主动跳转B页面,并且能正确返回A

阅读 12.4k
3 个回答

在 A 页面写一个事件,然后回退是可以的

document.getElementById("btn").addEventListener('click',function(){

    window.location.href = "https://baidu.com";

})

问题解决了吗?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题