So narrowing this down...
The way you have to come at this is to monitor the pagecontainerbeforechange event. From there you have to look at the ui.prevPage[0].id and see if it's the page you care about. In my case I used a switch statement:
- $("body").on("pagecontainerbeforechange",
function( event, ui ) { switch(ui.prevPage[0].id)
{
case "profilePage":
if (profile.bDirty_flag)
{
if(confirm("You have unsaved changes. Press OK to leave them or Cancel to stay and save them.") == false)
{
event.preventDefault();
event.stopPropagation();
return(false);
}
}
break;
default:
break:
}
- });
You CAN'T use any of the traditional confirm() options such as the phonegap plugin or ANY of the jquery plugins. You need something that will BLOCK until an answer is given. (The phonegap plugin is non-blocking and returns true so jquery will allow the page change while the dialog is still displayed.)
For those of you who don't know, javascript is "asynchronous" meaning that multiple processes (called threads) can happen at once. This allows things like ajax to execute while the user is active in the foreground /displayed page.
Blocking is something (usually a function) that prevents additional asynch calls from being started and call backs from existing asynch calls from being executed until the blocking function completes. With a blocking call active, an asynch callback (i.e. .done() or .always() ) won't be processed until the blocking call (i.e. confirm() ) completes.
Non-blocking is something (a function) that allows all operations to continue while the non-blocking function does its thing. For instance, an ajax call is non-blocking and will happen in the background while the user is doing their thing in the foreground. If an ajax .done() or .always() needs to be called and a blocking call is not happening, those calls get executed. If a blocking call is active, once it has completed, the asynch calls get executed.
The windows confirm() is a blocking call and will BLOCK asynch calls and wait until the user makes a selection. All the other UI stuff is non-blocking.