I have reg forms which have next and previous buttons and switch sections (showing and hiding them) with jQuery. I saw all plugins are using # tag and routes , but I can't use that. Is it possible to save this action somehow? For example, when I click back in the browser it needs to do the same action as when I click on the back button on the form. Is there any way to do this?
Asked
Active
Viewed 685 times
2
-
You can't overwrite the default action for browser buttons, but you can [read which button was pressed](http://stackoverflow.com/questions/18211984/how-to-control-back-button-event-in-jquery-mobile). – René Roth Apr 10 '14 at 13:56
-
You could save the state of the page in a cookie? This is how it is achieved for online shopping websites to save "items" while you can simply use just to store what was selected or changed. – Dean Meehan Apr 10 '14 at 13:57
-
What is the reason you can't use the available history plugins? Tying the URL to the state of the page is probably the best way to make your application's back and next buttons behave the same as the browser's. – Matt Apr 10 '14 at 14:17
-
@matt because my steps library dont work that way right now, its only hiding and showing divs – Sredoje Cutovic Apr 10 '14 at 14:35
-
Can't you just determine which div to show when the page is loaded based on the requested URL? – Matt Apr 10 '14 at 14:57
1 Answers
-1
You could try this jQuery Code:
$(window).on("navigate", function (event, data) {
var direction = data.state.direction;
if (direction == 'back') {
// do something
}
if (direction == 'forward') {
// do something else
}
});

user2718671
- 2,866
- 9
- 49
- 86