Phonegap navigator.app.backHistory / window.history.back not working on Blackberry Playbook

Manish Pradhan picture Manish Pradhan · Feb 6, 2012 · Viewed 9.4k times · Source

On the Blackberry playbook, the normal window.history.back does not work. Tested on the simulator....

So, I attempted this in the index.html

window.history.back = navigator.app.backHistory;

This gives control to the Phonegap function, but at run time it throws an error:

"Error: Status=2 Message=Class App cannot be found"

Here is the Phonegap (1.4.1) function:

/**
 * Navigate back in the browser history.
*/
App.prototype.backHistory = function() {
    // window.history.back() behaves oddly on BlackBerry, so use
    // native implementation.
    console.log("in backHistory");
    PhoneGap.exec(null, null, "App", "backHistory", []);
};

Any clues?

Answer

Zorayr picture Zorayr · Aug 6, 2012

Instead of overwriting window.history.back, you could write a generic back function that can act depending on which function is defined:

function goBack(){
    if (typeof (navigator.app) !== "undefined") {
        navigator.app.backHistory();
    } else {
        window.history.back();
    }
}

I am not sure if this answers your question, but I have been using this approach to enable testing on both mobile devices and desktop browsers.