Question

In my application i'm creating a WL.TabBar object for iOs and Android environments, like a navigation menu. To emulate the back-button of jquery i'm using a simple function like this

function back(){
   history.back();
   return false;
}

function forward(){
   history.forward();
   return false;
}

in iOs emulator it works but in Android no. I'm using an Android 2.2 virtual device.

EDIT: here is the code on android/js/[AppName].js file, also the same of iOs environment.

function wlEnvInit(){
wlCommonInit();
// Environment initialization code goes here

   navigation.init();
   navigation.addItem("item1",back,"Back",{});
   navigation.addItem("item2",forward,"Forward",{});
   navigation.setVisible(true);

}

var navigation = WL.TabBar;

function back(){
   window.history.back();
   return false;
}

function forward(){
   window.history.forward();
   return false;
}
Was it helpful?

Solution

This problem seems to be unique to Android 2.x. Your code works fine on Android 4.x. For some reason, windows.back()/windows.forward() has no effect when called directly out of the tab bar click handler on Android 2.x. You can work around this by using a short timeout:

function back() {
setTimeout(function() {
    window.history.back();
}, 100);
return false;
}

function forward() {
setTimeout(function() {
    window.history.forward();
}, 100);
return false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top