baker icon indicating copy to clipboard operation
baker copied to clipboard

Back button

Open ClovisMarsupial opened this issue 14 years ago • 7 comments

Hello Everyone. I'm trying to implement a back button on a page that would return to the previous page viewed. Example, if I am on page 3 and click on a link that leads me to page 9, I want a button in that page that would navigate back to page 3 (or page 8, or page 10 - depends of the last page viewed). Just like the window.history.back() javascript. Any thoughts ? Best Wishes

ClovisMarsupial avatar Aug 15 '12 01:08 ClovisMarsupial

Did you try simply linking the page you want to jump to?

So if from page 8.html you want to jump to to 7.html just put a link <a href="7.html"> and it should work.

folletto avatar Aug 15 '12 17:08 folletto

Yeah, that's not it (but thanks anyway). I'll try to be more clear, for example - I can get to page 8 through: 1.index 2.page 3 (link to page 8) 3.page 7 (traditional navigation - swiping left) 4.page 9 (traditional navigation - swiping right) I want a link in page 8 that gets me back to page I was (3, 7, 9 or anyone-through index). How to achieve that ? I've tried javascript window.history.back() , it was a no go. Regards

ClovisMarsupial avatar Aug 15 '12 20:08 ClovisMarsupial

I think there's no way to achieve that. I note this as a feature request. :)

Thinking again, you might be able to do it using JavaScript and some form of local storage, to store the page where you were and recall it from a function. It might work.

folletto avatar Aug 15 '12 21:08 folletto

I've managed to do that. Sure it's a workaround and by far not the best way to do it, but it works for my purposes. This is what I did:

  • Created a new property (NSString) called previousPagePath.
  • in scrollViewDidEndDecelerating and shouldStartLoadWithRequest (webview), I set this variable with the path of the current page before calling the new page.
  • in shouldStartLoadWithRequest (webview), I added a new 'else if' in the 'schemes loop' with a new url scheme called "back". Then I used the same methods of 'file://' to call the page with previousPagePath.
  • in my HTML file I added a button with href back://. Done. Sorry about the mess...English is not my main language. Best Wishes.

ClovisMarsupial avatar Aug 15 '12 21:08 ClovisMarsupial

Well, that's probably still a good start ;)

folletto avatar Aug 15 '12 21:08 folletto

You can probably do that with javascript and localStorage.

Here's the idea that you need to apply on each page (I didn't tried it)

  • store the current page name with localStorage on blur event
  • on focus event, update your back button link with the value from localStorage

If that's possible to do that with html / javascript, I think a native solution would be better.

benoitchantre avatar Mar 27 '13 16:03 benoitchantre

I'm closing this since the discussion stopped and we evaluated it's better as a JavaScript solution than a platform solution. :)

folletto avatar May 26 '13 13:05 folletto