
- jQuery Mobile Tutorial
- jQuery Mobile - Home
- jQuery Mobile - Overview
- jQuery Mobile - Setup
- jQuery Mobile - Pages
- jQuery Mobile - Icons
- jQuery Mobile - Transitions
- jQuery Mobile - Layouts
- jQuery Mobile - Widgets
- jQuery Mobile - Events
- jQuery Mobile - Forms
- jQuery Mobile - Themes
- jQuery Mobile - CSS Classes
- jQuery Mobile - Data Attributes
- jQuery Mobile Useful Resources
- jQuery Mobile - Interview Questions
- jQuery Mobile - Quick Guide
- jQuery Mobile - Useful Resources
- jQuery Mobile - Discussion
Adding Back Button to Header
Description
jQuery mobile framework generates a back button on a header, when a header has a data-add-back-btn = "true" attribute or the page plugin's addBackBtn option is set to true.
Adding data-rel = "back" on an anchor will take you to the history entry, ignoring the default href.
You can provide the back button text using data-back-btn-text = "previous" attribute or you can set plugin's options in the following way.
$.mobile.toolbar.prototype.options.backBtnText = "previous";
Example
Following example demonstrates the use of adding back button to header in jQuery Mobile.
<!DOCTYPE HTML> <html> <head> <title>Adding back button to header</title> <link href = "//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" rel = "stylesheet"> <script src = "//code.jquery.com/jquery-1.8.1.min.js"></script> <script src = "//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> </head> <body> <div id = "page1" data-role = "page" data-add-back-btn = "true"> <div data-role = "header"> <h2>Header</h2> </div> <div data-role = "content"> Go to <a href = "#page2">page2</a> </div> <div data-role = "footer"> <h2>Footer</h2> </div> </div> <div data-role = "page" data-add-back-btn = "true" data-back-btn-text = "Previous" id = "page2"> <div data-role = "header"> <h2>Header</h2> </div> <div data-role = "content"> Go to <a href = "#page1">page1</a> </div> <div data-role = "footer"> <h2>Footer</h2> </div> </div> </body> </html>
Output
Let's carry out the following steps to see how the above code works −
Save the above html code as toolbar_back.html file in your server root folder.
Open this HTML file as http://localhost/toolbar_back.html and the following output will be displayed.
jquery_mobile_widgets.htm
Advertisements