Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate History enteries using History.pushState in Chrome/Safari

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);
});
like image 959
Alex Avatar asked Mar 21 '23 14:03

Alex


1 Answers

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.

like image 73
Iain Y Avatar answered Apr 25 '23 15:04

Iain Y