jaunesarmiento / fries

Fries helps you prototype Android apps using HTML, CSS, and JavaScript.
MIT License
1.55k stars 222 forks source link

Window.history not working well with stack.js page that has tabbed navigation #25

Closed aymanfarhat closed 11 years ago

aymanfarhat commented 11 years ago

I have a page that I am opening via stack.js which has some tabs in it. I added a back button for the page which would execute window.history.go(-1); to go back to index.html.

The problem is that, the user would have to click so many times on the back button to make it go back within a stack.js page which has tabs, after navigating through them. This is because the back button would be going back through the previously viewed tabs on the page before going back to index.html

I could have directly linked back to index.html but I have dynamically loaded data there which I don't want to lose.

Haven't come up with a fix for this yet, looking for a simple workaround first.

jaunesarmiento commented 11 years ago

Hi @aymanfarhat, I'm aware of this issue and has fixed it in the current wip version. The fix was adding event.preventDefault() to tabs.js. Please have a look at this commit: https://github.com/jaunesarmiento/fries/commit/03bf6a3de062618f0378288a307c1ecddbf01508

jaunesarmiento commented 11 years ago

The issue was caused by tabs.js appending the #href to the address bar, causing stack.js to pop these first.

aymanfarhat commented 11 years ago

What I find weird is that the fix works fine when testing on the browser yet doesn't work in Phonegap

EDIT:

It still didn't work on Phonegap so I ended up with a workaround(temporary) where for each hyperlink of a tab I added onClick="retun false" in order to prevent propagation and the pushing of the hashbang page into history. preventDefault for the touchend on the window didn't cut it, although it does on chrome which is baffling.

jaunesarmiento commented 11 years ago

Won't event.stopPropagation() work? Maybe call it after calling event.preventDefault()?

aymanfarhat commented 11 years ago

I can confirm that calling e.stopPropagation() before or after preventDefault() isnt really making any difference.

jaunesarmiento commented 11 years ago

That is really odd. I really can't work on it at the moment due to the lack of an Android phone. I will however be able to buy one within the week. You can try to find a solution to this if it's not too much to ask from you.

aymanfarhat commented 11 years ago

Yes definitely I'll look again into it when I have time and report back.

jaunesarmiento commented 11 years ago

Great, thanks @aymanfarhat! :)

jaunesarmiento commented 11 years ago

Oops, forgot to close this issue. This is already fixed in the wip-1.0.1 branch.