jquery-archive / jquery-mobile

jQuery Mobile Framework
https://jquerymobile.com
Other
9.7k stars 2.41k forks source link

Loss of database reference when pressing the phone's back button (phonegap) #736

Closed udos86 closed 13 years ago

udos86 commented 13 years ago

Hi,

I think I discovered a bug when using jQuery Mobile in combination with the latest version of phonegap and Web SQL Database.

In my app I do open a local database as soon as the document is ready (var db = openDatabase(...)). The main page contains a button which stores some simple string values into the database. No problem so far.

Now here it comes: every time I slide to another page via $.mobile.changePage() and then press the back button of the phone (below the display) to return to the main page again, I'm no longer able to store values into the database. Just nothing happens when pressing the store button. There's not even an SQL error fired. And the command line "alert(db.version);" just creates a total blank alert window. To me it seems that somehow the reference to the database gets completely lost on the reverse slide.

The weird thing is that everything works fine as long as I use the jQuery Mobile default back button in the header of the actual page instead of the external back button of the phone.

This behaviour shows up on a HTC Hero as well as on a HTC Desire HD.

udos86 commented 13 years ago

Hi,

I'm very sorry I filed this as a jQuery Mobile bug. After some research I found out that this problem is definetely caused by phonegap.

You can fix it by adding the following lines of code to your JavaScript file:

document.addEventListener("deviceready", function(){

device.overrideBackButton(); document.addEventListener("backKeyDown", function(){
history.go(-1); }, false);

}, false);

jQuery-syntax $(document).bind(..) seems not work to bind the "deviceready" phonegap-event.

Sorry again!