【问题标题】:history.pushState and window.location.href out of synchistory.pushState 和 window.location.href 不同步
【发布时间】:2012-09-03 10:42:26
【问题描述】:

我在 Android 移动设备上看到一个与 History API 相关的奇怪问题。我运行一些代码来使用history.pushState 更新页面url,然后检查window.location.href 的值。我希望href 的值等于我刚刚推送的值,但它仍然具有以前的值。当我检查浏览器 url 栏时,位置已正确更新。此代码重现了该问题:

function go(){
    console.log(window.location.href); // this shows url of '.../page1.html'
    window.history.pushState({}, '', './page2.html');
    console.log(window.location.href); // this still shows url of '.../page1.html'
    // browser address bar shows url of '.../page2.html'
}

我在默认的 Android 2.3.4 浏览器上看到了这个问题,当我在桌面浏览器中运行相同的代码时,它的行为与我预期的一样(即 window.location.href 具有我推送的值) - 任何人都可以确认这是浏览器错误,而不是预期行为?

【问题讨论】:

标签: javascript android mobile browser-history


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2018-05-14
    • 1970-01-01
    • 2011-01-25
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 2012-11-28
    • 1970-01-01
    相关资源
    最近更新 更多