Duplicate History enteries using History.pushState in Chrome/Safari

安稳与你 提交于 2020-06-10 04:58:12

问题


I am having a strange problem in Chrome and Safari using History.js from https://github.com/browserstate/history.js/

If I click on several different ".node" items and then look at my browsers history, I have duplicate entries for each click and need to his the back button twice to go back the the last "real" state. I added a console.log(id) in and can confirm that the event is only firing the one time.

In Firefox it works as expected. I am only seeing the duplicate history items in Chrome and Safari.

$( "body" ).delegate( ".node" , "click", function(){
    id = $(this).data('id');
    History.pushState({"Foo":"Bar","ID":id}, "Title for "+ id, "/item-"+id);
});

回答1:


I was having a similar problem to this in Chrome (wasn't happening in IE and Firefox) and it turned out the extra history entries weren't being added by pushState but happened when I altered the src attribute on iframes via javascript.

Even though they were loading from a remote site (Vimeo in this case) they were showing up in the back/forward button's history as duplicates of the current page and I'd have to click back multiple times.

I've not tested this further so I don't know if this is unique to iframes or if it could be caused by altering any elements src attributes.



来源:https://stackoverflow.com/questions/20034274/duplicate-history-enteries-using-history-pushstate-in-chrome-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!