I have a function named back()
which will be used for ajax calls. Actually I have an array stack contains last 5 search results and that back function will switch to the previous result set (according to that array stack) and it even changes the URL using window.history.pushState()
when you click on the back button.
That back button I was talking about, is an element inside the browser which revokes back()
function. Now I want to revoke back()
function also when user click on the back button of the browser. Something like this:
window.onhashchange = function() {
back(); // this function also changes the url
}
But sadly window.onhashchange
will be revokes twice when I click on the back of the browser. Because window.onhashchange
will be revoked when you change the URL using window.history.pushState()
.
Anyway, how can I detect what things changes the URL? Either my JS code or the back button of the browser?