I have a Single Page Application running in PhoneGap, and driving through content with Sammy.js
Consider this:
The home page is domain.com/#/panel
Then I click on Reglas(regulations) The location.hash updates to #/regulations
After this I can see the current regulations, when I click anyone of this, I update again the location.hash to #/regulation/1 (or whatever number the regulation is):
Here is the deal:
I have a back button inside my app in the navbar next to the screen title, and it have a click listener with this:
$('back').click(function(e) {
e.preventDefault;
// window.history.back();
history.back();
});
It works well when I'm at the 2nd screen (#/regulations), it brings me back to #/panel. But when I'm on a 3rd screen (#/regulation/1) it brings again to #/panel instead of the #/regulations section.
When I click browser's backbutton it works very good but somehow when I click MY back button it doesn't work properly.
I have read some topics about this, like Mozilla's one:
Like Mozilla said, it should work exactly as if I clicked the browser's back button, but it doesn't.
I have tried with:
window.history.back();
window.history.go(-1);
history.back();
history.go(-1);
It seems not working with anything.
Can anyone help?
Sorry little mistakes happens to anybody:
e.preventDefault(); (parentheses) and #back (sharp) were the problem.
However, if anybody get in this trouble, Mozilla had the reason, any of this lines work exactly as if the user clicks browser's back button:
$('#back').click(function(e) {
e.preventDefault();
window.history.back();
// window.history.go(-1);
// history.back();
// history.go(-1);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With