在Safari中,如果加載了iframe
,並且用戶通過後退或前進來更改歷史記錄狀態,則不會觸發popstate
事件,從而導致應用程序狀態和窗口位置不同步。爲什麼Safari在加載iframe時未觸發popstate?
我認爲一個活躍的XHR請求會導致相同的行爲,但我還沒有能夠確認。
這裏有一個的jsfiddle,讓您可以輕鬆地重現該問題: http://jsfiddle.net/neonsilk/muHk8/
您只需要點擊鏈接/按鈕的順序,從1至6
在Safari 5.0.5,輸出爲:
(逆時間,重要的部分是在頂部的狀態相比)
[1305665493096]/
[1305665493096] vs
[1305665493096] /node
---------------
[1305665489955] iframe loaded
---------------
[1305665489806] (did popstate or $.address change trigger?)
[1305665489805] called history.back()
[1305665489805] appended iframe
---------------
[1305665488428] popstate: /node
[1305665488427] $.address change: /node
---------------
[1305665487821] popstate:/
[1305665487821] $.address change:/
---------------
[1305665487179] $.address change: /node
---------------
[1305665486606] $.address change:/
---------------
[1305665485732] iframe loaded
---------------
[1305665485569] $.address change: /neonsilk/muHk8/show/
[1305665485568] $.address init
然而,在瀏覽器(11)或Firefox(4.0),輸出的樣子:
(注意,狀態是同步)
[1305665609499]/
[1305665609499] vs
[1305665609499]/
---------------
[1305665608360] iframe loaded
---------------
[1305665607770] popstate:/
[1305665607770] $.address change:/
[1305665607758] (did popstate or $.address change trigger?)
[1305665607758] called history.back()
[1305665607758] appended iframe
---------------
[1305665606870] popstate: /node
[1305665606869] $.address change: /node
---------------
[1305665606150] popstate:/
[1305665606149] $.address change:/
---------------
[1305665605551] $.address change: /node
---------------
[1305665604808] $.address change:/
---------------
[1305665603354] iframe loaded
---------------
[1305665602688] $.address change: /neonsilk/muHk8/show/
[1305665602682] $.address init
[1305665602676] popstate: /neonsilk/muHk8/show/
這是在Safari中的錯誤?如果是的話,有沒有人發現一種解決方法?
(這也是有趣的是,Firefox和Chrome的火popstate
事件在頁面加載)。