1

I'm new to Mobile development. I wrote a simple web app for mobile platforms which contains two HTML files: index.html, info.html. In the main page index.html, there is a hyperlink that allows user to navigate to the next HTML page: info.html like this:

<a href="info.html">Next</a>

Both these two HTML files are located in the same directory. I tested it in my desktop browser and it works fine. But problems occurred when I built and loaded the app to my Android smartphone. If I click "Next" link as given above in index.html, it will go the info.html page without any problems. But when I used the "Back" button on my smartphone, it got stuck there and didn't go back to the previous page index.html as expected. So what is the problem here? I'm using MoSync SDK for HTML web app development tool.

tonga
  • 11,749
  • 25
  • 75
  • 96

2 Answers2

1

I don't have an android phone myself. Are you deleting the history by accident, if not try placing your own back button in it might not work but it could help.

Insert this code in the head of your HTML document:

<script>
function goBack()
  {
  window.history.back()
  }
</script>

Then insert this code where you want the button to appear:

<input type="button" value="Back" onclick="goBack()">

To find out more about the javascript back button: http://www.w3schools.com/js/js_window_history.asp

I hope this helps.

Blob
  • 97
  • 1
  • 1
  • 6
  • Thanks. This works by adding my own back button in the page. However, what if I want to use the "Back" button on the touchscreen located at the bottom of my Android phone to achieve the same "navigate back" behavior? – tonga Jan 16 '13 at 18:54
1

try this, it worked for me

                      ` //back button (on Android).
                      document.addEventListener(
                    "backbutton",
                 function()
                        {
                     window.history.back()
                   },
                   true);`   

AND this one is to exit the app

                    `// Close the application when the back key is pressed.
               document.addEventListener(
                        "backbutton",
                       function()
                     {
                        mosync.app.exit();
                  },
                 false);`

they are both javascripts files so put them in the script tags put this script on the fist page of your android app