Page 1 of 1

back button android

Posted: Tue Dec 29, 2015 1:06 pm
by EJLD

hi there, looked at that link
http://docs.phonegap.com/en/2.0.0/cor...
which i found in a closed topic on this forum
I placed the code in my page. however, does not work as expected. the listener fires something when backbutton is pressed. but, that "something" is not the code I inserted. in fact, it keeps showing the spinning circle as it was stuck executing something in loop.
anybody has ever succeeded at overriding that backbutton default event ?
thk you very much for any advice in advance
Eric


back button android

Posted: Tue Dec 29, 2015 4:03 pm
by Serhii Kulibaba

Hello,

Have you set 'backbutton' event for that page? What exactly have you used there?


back button android

Posted: Tue Dec 29, 2015 4:33 pm
by EJLD

thks for your prompt reply Sergiy
I would like to fire the onbeforeunload popup when pressing the device backbutton.
I have tried several ways :
a/ code as per phonegap link in msg above: didn't fire anything
b/ set the backbutton event from the appery UI panel : didn't fire anything
c/ code the js listener window.onbeforeunload=myf(); but quite inconsistent. the popup shows up or doesn't show ... strange behavior on pressing backbutton and reaching the previous page opened in the same window (even though this event listener is consistent when unloading the page from the url bar using a new url address).

not too sure, all that is clear enough for you to help me.

just ask you to give me some direction on how can I get the backbutton event within a HTML site (not a built up hybrid app). any clue ?

thks again
Eric


back button android

Posted: Wed Dec 30, 2015 11:17 am
by Alena Prykhodko

Hello,

Use this code instead:

prewindow.addEventListener("hashchange", onHashChanged, false);

function onHashChanged(event) {
var msg = "Navigating from: " + event.oldURL +
"\nNavigating to: " + event.newURL;
alert(msg);
}
/pre

You can track when you navigate to another page and check it when executing custom logic.