Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquerymobile phonegap back-button get previous state

I'm building an little mobile app and I got a question about JQM.

When the user is logged in the user will be redirected to page A. Page A is loaded with the loadPage from JQM (example: $.mobile.loadPage("pageA.html"))

After the page is loaded, I do an AJAX-call because I pull some data from a database and change the content on page A. From page A, I can go to page B. page B has an back-button. When I click on the back-button, the app slides back to the state without the AJAX content. Is there a way to fix this?

Thanks

like image 856
Kevin Gorjan Avatar asked Mar 14 '12 20:03

Kevin Gorjan


1 Answers

By default, jQuery Mobile will remove any page brought into the DOM via AJAX once the user navigates away from the page. If you want to disable this feature for a specific page you can add the data-dom-cache attribute to the data-role="page element for the page and set it to true:

<div data-dom-cache="true" data-role="page" id="pageA">
    ...
</div>

Source: http://jquerymobile.com/demos/1.1.0-rc.1/docs/pages/page-cache.html

This feature was added to jQuery Mobile to help control the size of the DOM so less browser crashes will occur. If you just want to keep a single page in the DOM then make sure it's not a huge page that will bog-down the device.

like image 71
Jasper Avatar answered Sep 29 '22 20:09

Jasper