NavGroup in a webview?

You must Login before you can answer or comment on any questions.

Hey, does anyone know how to set a nav bar to a webview so I can implement a back button to close it when a user is ready. The segment of code below is what I have for the webview as well a the event listener for the button which which launches the webview from the main screen

webViewButton.addEventListener('click',function(e){
    webWindow.open();
    webNavGroup.open();
});
var webWindow = Titanium.UI.createWindow({title: "Web"});
 
var webNavGroup = Titanium.UI.iPhone.createNavigationGroup({
    barColor: 'black',
    window:webWindow
});
 
var webView = Titanium.UI.createWebView({url: 'http://www.google.com.au'});
 
var webBackButton = Titanium.UI.createButton({
    title: "Back",
    center: {
        x: platformWidth * 0.5,
        y: platformWidth * 0
    }
});
 
webBackButton.addEventListener('click',function(e){
    webWindow.close();
    webNavGroup.close();
});
 
webWindow.add(webNavGroup);
webWindow.add(webView);
webWindow.add.setLeftNavButton(webBackButton);
Any assistance would be greatly appreciated.

Thanks in advance

2 Answers

Accepted Answer

Hi Brett, you can try like this:-

// app.js code
 
var RootWindow = Titanium.UI.createWindow({
    url : 'rootWindow.js', //RootWindow.js
    title : 'RootWindow',
    backgroundColor : '#fff'
 
});
 
var baseWin = Ti.UI.createWindow();
var navGroup = Ti.UI.iPhone.createNavigationGroup({
    window : RootWindow
});
 
RootWindow.navGroup = navGroup;
baseWin.add(navGroup)
baseWin.open(); 
 
//rootWindow.js code
 
var currentWin = Ti.UI.currentWindow;
 
var button = Ti.UI.createButton({
    title:'webView',
    top:20,
    width:150,
    height:50,
    left:20
});
 
button.addEventListener('click',function(e){
    var win = Titanium.UI.createWindow({
        title : 'WebView',
        backgroundColor : '#fff'
    });
    var webView = Ti.UI.createWebView({
        url:'https://www.google.com'
    });
    win.add(webView);
    win.navGroup = currentWin.navGroup;
    currentWin.navGroup.open(win);
});
 
currentWin.add(button);

just createThese two files with the following code and see how it works.

— answered 8 months ago by Ashish Nigam
answer permalink
1 Comment
  • if you find any redundancy in this code, so you can optimize it as per your need. this is just for your help and concept.

    — commented 8 months ago by Ashish Nigam

Your Answer

Think you can help? Login to answer this question!