1

用于 pushState 的代码

        window.history.pushState({"html":r[0],"pageTitle":r[1], 'bread_crumbs': r[2], 'page': r[3], 'parentid': r[4], 'pageid': r[5]},"", h);

用于检查状态的代码

window.onpopstate = function(e) {
    console.log(e.state.page+'|'+location.href);

假设我访问了 10 个页面 - 当我单击第 5 页时,它在浏览器中显示了很好的标题。但由于某种奇怪的原因,它输出了第 4 页。

如果我单击后退按钮,它会起作用,您可能知道 - Chrome 会在单击第二个鼠标按钮后显示所有步骤。所以这里发生了这个问题。

谢谢你。

你可以在这里试试 http://demo.ajax-cart.com/

点击 1. 测试类别 2. 品牌 3. 博客 4. 关于 5. 新闻

使用返回按钮返回“我们的博客” - 您将看到“品牌”。

4

1 回答 1

0

我找到了解决方案

它是

            document.title = r[1];
            window.history.pushState({"html":r[0],"pageTitle":r[1], 'bread_crumbs': r[2], 'page': r[3], 'parentid': r[4], 'pageid': r[5]},"", h);

但它必须是

        window.history.pushState({"html":r[0],"pageTitle":r[1], 'bread_crumbs': r[2], 'page': r[3], 'parentid': r[4], 'pageid': r[5]},"", h);
        document.title = r[1];
于 2018-05-05T20:56:00.830 回答