void page_BackKeyPress(object sender, CancelEventArgs e)
{
if (OverrideBackButton)
{
try
{
CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('backbutton');" });
e.Cancel = true;
}
catch (Exception ex)
{
Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message);
}
}
else
{
try
{
PageDidChange = false;
Uri uriBefore = this.Browser.Source;
// calling js history.back with result in a page change if history was valid.
CordovaBrowser.InvokeScript("eval", new string[] { "(function(){window.history.back();})()" });
Uri uriAfter = this.Browser.Source;
e.Cancel = PageDidChange || (uriBefore != uriAfter);
}
catch (Exception)
{
e.Cancel = false; // exit the app ... ?
}
}
}