Working with back buttons
Depending on your user's hardware, they may or may not have a physical back button. For devices that do, such as Android phones, hitting the back button will work just fine in a jQuery Mobile application. Whichever page the user was on previously will be loaded as soon as the button is clicked. But on other devices, such as the iPhone, there is no such button to click. While you can provide links to navigate around pages yourself, jQuery Mobile provides some nice built-in support for navigating backwards out of the box.
There are two ways you can add an automatic back button. The code in Listing 3-4
shows a simple two-page jQuery Mobile website. In the second page, we've added a new data attribute, data-add-back-btn="true"
. This will create a Back button in the header of the second page automatically. Next, we also added a simple link in the page content. While the actual URL of the link is blank, make note of the data-rel="back"
attribute...