cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jesse MacFadyen (JIRA)" <>
Subject [jira] [Commented] (CB-3621) Overriding Back Button behavior can lead to inconsistent state
Date Tue, 11 Jun 2013 01:51:20 GMT


Jesse MacFadyen commented on CB-3621:

Here is a workaround for the time being.

In javascript, supply your own version of window.history.back like so:
var _back = window.history.back;
window.history.back = function () {
  // to prevent the default behavior(exit) return a truthy value, ie. true, 1, "You can never
go back!", ...

Inside CordovaView.xaml.cs method 'page_BackKeyPress'

void page_BackKeyPress(object sender, CancelEventArgs e) ...

replace the few lines after "//calling js history.back with result in a page change if history
was valid."
like so:
// calling js history.back with result in a page change if history was valid.
// returning a truthy value will prevent the default behavior -jm

string strRet = CordovaBrowser.InvokeScript("eval", new string[] { "(function(){var ret =
window.history.back(); if(ret)return 'skipDefault';})()" }) as string; 
Uri uriAfter = CordovaBrowser.Source;

e.Cancel = PageDidChange || (uriBefore != uriAfter) || !string.IsNullOrEmpty(strRet);


The above fix will be available for WP7+8 in 2.9.0.
> Overriding Back Button behavior can lead to inconsistent state 
> ---------------------------------------------------------------
>                 Key: CB-3621
>                 URL:
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: WP7, WP8
>    Affects Versions: 2.8.0
>            Reporter: Jesse MacFadyen
>            Assignee: Jesse MacFadyen
>             Fix For: 2.9.0
> The current implementation does the following:
> - if the app has overridden the back button, by using document.addEventListener, then
the backbutton event is passed to the page, and discarded.
> - else, the library will call window.history.back and if the page changes, discard the
> In all other cases the event will be passed to the OS and the app will exit.
> It is possible that an app is overriding the backbutton, but still needs the ability
to exit at some point ( in response to a backbutton event ).
> If the page history has changed, then the framework would swallow the event, so it is
impossible to get this behavior.
> We need to either add a programmatic way to exit the app in response to a back-button
press, or find a way to signal the framework that even though I am overriding the backbutton,
the app should still pass the event on to the OS.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message