5

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 enter image description here

Then I click on Reglas(regulations) The location.hash updates to #/regulations

enter image description here

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):

enter image description here

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: enter image description here

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?

4
  • 2
    Check out pushState and popState : developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/… Commented Mar 24, 2015 at 4:08
  • 1) try window.history.length; to see how many links you have in history when you are in 3rd screen ! Commented Mar 24, 2015 at 12:18
  • 2) what happens if you try from 3rd screen history.go(-2) ? Commented Mar 24, 2015 at 12:22
  • I had grammar mistakes in my code. Thank you guys for the support. Commented Mar 24, 2015 at 23:40

1 Answer 1

0

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); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.