I'm having an issue with the following situation.
- User visits site
- User clicks link which uses history.pushState to update the url
- Partial page content loaded via ajax (using jQuery)
- User clicks regular link which loads a new page
- User clicks back to return to the pushState entry
- The page now displays only the page partial that was retrieved via ajax
I've souped up a site using pushState for various things and the result is a shockingly responsive web app, but this issue is preventing me from using this.
Here's a sample of the code:
$('a').live('click', function(){
history.pushState({}, '', this.href);
popstate(this.href);
return false;
});
popstate = function(url){
$('#content').load(url);
}
window.onpopstate = function(event){
popstate(window.location.href);
event.preventDefault();
}
Notes:
- When placing an alert in the window.onpopstate function it appears that the event is NOT triggered at step 5. Is this a bug?
- The issue only occurs when ajax is used.
- I have had to separate the popstate function so I can call it after pushState. Is there a way to manually trigger the window.onpopstate event?