Charles Lillo
Charles Lillo

Reputation: 365

Triggering a back button in webview

I'm using titanium studio to package an app we are currently working on, and one of the pages is a webview to a mobile version of our site. This all works and looks great, but when the user navigates to a new url, going backwards is impossible. I've tried several methods to set up a back button/ navigation group to solve this problem, but nothing seems to work. What would be the best way to either to load the next page into the nav group, or trigger a back button to appear upon a new page being loaded?

So far I have tried:

Upvotes: 0

Views: 1557

Answers (1)

Dhairya Vora
Dhairya Vora

Reputation: 1281

var btnBack = Titanium.UI.createButton({
    title : '< ',
    top : 0,
    left : 0,
    height : '10%',
});
var btnFwd = Titanium.UI.createButton({
    title : ' >',
    top : 0,
    right : 0,
    height : '10%',
});
var webView = Titanium.UI.createWebView({
    url : 'http://gooogle.com',
    canGoBack : true,
    canGoForward : true,
    top : '10%',
    height : '90%',
});
btnBack.addEventListener('click', function() {
    webView.goBack();
});
btnFwd.addEventListener('click', function() {
    webView.goForward();
});
var win1 = Titanium.UI.createWindow({  
    backgroundColor:'#fff',
});
win1.add(btnBack);
win1.add(btnFwd);
win1.add(webView);
win1.open();

Does this solve your issue? if this doesn't, please clarify what do you need to do??

Upvotes: 3

Related Questions