Desktop: Check if window is already open and if so replace content

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

I am making a simple app that on the main page there is a menu that opens a window and displays content. If that window is still open and they click on another menu item in the main window I want the new content to appear in the window that is open.

Here is my code to open the window:

function popupWindow(page){

        var myWin = Titanium.UI.createWindow({
            id: "propertyWindow",
            title: "Core Reading with Jazzles",
            url: "app://" + page,
            width: screen.width - 100,
            height: screen.height - 100,
            maximizable: false,
            minimizable: false,
            closeable: true,
            resizable: false,
            fullscreen: false,
            maximized: false,
            minimized: false,
            usingChrome: true,
            topMost: true,
            visible: true,
            transparentBackground: false,
            transparency: false
        });

        myWin.open();
        myWin.CENTERED;
}

How to I check if the window is already open? and if it is change the URL?

1 Answer

Gary,

Off the top of my head, you could use either (haven't tested in actual code):

Titanium.UI.UserWindow.isActive

or

Titanium.UI.UserWindow.isCloseable

or

Titanium.UI.UserWindow.isVisible

— answered 2 years ago by Alan DuBoff
answer permalink
1 Comment
  • I am new to all this, I tried this but know it won't open any window:

    if (myWin.isActive) {
    
        myWin.setURL("app://" + page);
    
    } else {
    
            var myWin = Titanium.UI.createWindow({
                id: "propertyWindow",
                title: "Core Reading with Jazzles",
                url: "app://" + page,
                width: screen.width - 100,
                height: screen.height - 100,
                maximizable: false,
                minimizable: false,
                closeable: true,
                resizable: false,
                fullscreen: false,
                maximized: false,
                minimized: false,
                usingChrome: true,
                topMost: true,
                visible: true,
                transparentBackground: false,
                transparency: false
            });
    
            myWin.open();
    }
    

    — commented 2 years ago by Gary Collins

Your Answer

Think you can help? Login to answer this question!