Henry8
Henry8

Reputation: 264

Titanium Appcelerator - show back button in webview

I use a webview and I show an external page; I would like that the back button appears only if there is a web history. I saw that exist a canGoBack() function, but I don't know how use this function.

NB my user see the webview (back button must be hidden) if the user click on the link and the web page is changed, the back button should be appear... if the user go back to the webview home , the back button disappear.

This code is triggered only when i load the webview for the first time, if navigate the webview the function is ignored:

if(webview.canGoBack()){
    //webview.goBack();
    Titanium.API.log('1');
}
else{
    //win.close();
    Titanium.API.log('0');
}

I hope I was clear. Thanks

Upvotes: 1

Views: 1773

Answers (1)

Josiah Hester
Josiah Hester

Reputation: 6095

Put this in the load event:

webview.addEventListener('load', function() {
    if(webview.canGoBack()){
        //webview.goBack();
        Titanium.API.log('1');
    }
    else{
        //win.close();
        Titanium.API.log('0');
    }
});

The load event is called every time the page changes.

Upvotes: 2

Related Questions