【发布时间】: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 具有我推送的值) - 任何人都可以确认这是浏览器错误,而不是预期行为?
【问题讨论】:
-
caniuse.com/#search=history 查看“已知问题”标签
标签: javascript android mobile browser-history