2012-09-03 27 views
0

我在Android移動設備上看到與歷史API有關的奇怪問題。我運行一些代碼來使用history.pushState來更新頁面網址,然後檢查window.location.href的值。我期望href的價值等於我剛推出的價值,但它仍然具有以前的價值。當我檢查瀏覽器url欄時,位置已經正確更新。此代碼重現該問題:history.pushState和window.location.href不同步

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有值我推) - 任何人都可以確認這是一個瀏覽器錯誤,而不是預期的行爲?

+0

http://caniuse.com/#search=history 參見 '已知的問題' 選項卡 –

回答