小编ccr*_*san的帖子

history.back()不适用于Chrome中预期的HTML5历史记录API

history.back()函数应该让我回到使用HTML5历史API创建的历史记录中的一步.以下代码在Firefox中按预期工作,但在Chrome中不起作用:

<html>
    <script type="text/javascript">
        history.replaceState({path: '/home'}, '', '?page=home');
        history.pushState({path: '/second'}, '', '?page=second');
        console.log(history.state.path); // says "/second"
        history.back();
        console.log(history.state.path); // says "/second" but should say "/home"
    </script>
</html>
Run Code Online (Sandbox Code Playgroud)

在Chrome中,它会打印/second两次,而在返回后它应该打印/home.我错过了什么吗?

javascript html5 google-chrome html5-history

6
推荐指数
1
解决办法
975
查看次数

标签 统计

google-chrome ×1

html5 ×1

html5-history ×1

javascript ×1