I am writing a single page javascript application using the HTML5 History API. The application loads content via Ajax and internally maintains state information on the foreground screen using a screen stack.
I want to enable navigation with the back button, but I never want to the forward button to be enabled.
A couple quick bits of information:
- The user should only ever be able to go back, never forward
- Pressing browser back button closes the current page screen user is on and reloads the previous one
- Project is targeted towards the latest version of Chrome only, so other browsers implementations are not important
- I am using native JavaScript and jQuery only, I would like to do this without History.js
When I load a new screen I run the following line:
history.pushState(screenData, window.document.title, "#");
I bind to the popstate event via jQuery:
$(window).bind("popstate", function(event) {
if (event.originalEvent.state != null) {
// Logic that loads the previous screen using my screen stack
}
});
My application's history management is working, however when I go back the forward button is enabled. I need to figure out how to remove data from history
on the popstate
event.
Can I do this with replaceState? I'm not sure how to go about doing this...