I want to be able to add certain behavior when a user clicks browser "back" and "forward" buttons.
Is there a way to say with JavaScript something like this:
backButton.onclick = function() {
// do something
}
forwardButton.onclick = function() {
//do something else
}
Is there a way to do that directly with JavaScript, without relying on any plugin?
I want to be able to add certain behavior when a user clicks browser "back" and "forward" buttons.
Is there a way to say with JavaScript something like this:
backButton.onclick = function() {
// do something
}
forwardButton.onclick = function() {
//do something else
}
Is there a way to do that directly with JavaScript, without relying on any plugin?
Share Improve this question edited Jun 12, 2013 at 17:49 KeithRules asked Jun 12, 2013 at 17:11 KeithRulesKeithRules 2071 gold badge4 silver badges15 bronze badges 3- No. You're looking for the HTML5 history API. – SLaks Commented Jun 12, 2013 at 17:12
- 1 It has already been answered here: stackoverflow./questions/4840457/… – Antoine Commented Jun 12, 2013 at 17:15
- Modified the question to clarify – KeithRules Commented Jun 12, 2013 at 17:19
1 Answer
Reset to default 7window.addEventListener("popstate", function(e) { // if a back or forward button is clicked
// do whatever
}
Works only in HTML5-enabled browsers, though.
For other browsers support, look into History.js