Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiate Back/Forward click and History.pushState/replaceState in statechange event

I am using History.js plugin which support HTML 5 pushState and replaceState. The statechange is triggered when a user click back/forward button and when pushState/replaceState is used. I need to check whether statechange event is triggered from back/forward button or by using pushState/replaceState methods.

like image 728
Imran Qadir Baksh - Baloch Avatar asked Feb 27 '12 11:02

Imran Qadir Baksh - Baloch


2 Answers

I haven't looked at History.js, but Ben Alman's jQuery BBQ (Back-Button & Queue Library) is an excellent library that contains a 'hashchange' event. This might be different than what you are trying to do, though, since his library relies on hashtags in a URL, and not a browser's internal statechange. He's also got a repo on GitHub for hashchange.

like image 129
ariestav Avatar answered Oct 20 '22 08:10

ariestav


According to a discussion on the GitHub by the author, it is impossible to do that (from a year ago, can't find the link again). Your option really is to look for some kind of a workaround like breadcrumbs etc.

like image 37
eric.itzhak Avatar answered Oct 20 '22 07:10

eric.itzhak