Appcelerator Titanium has a rich set of Window management methods which are accessible with the UserWindow object and the Titanium.UI namespace.

The basics of opening up a new window in Titanium is as follows:

   var currentWindow = Titanium.UI.getCurrentWindow();
   var newWindow = currentWindow.createWindow('http://www.google.com');
   newWindow.setWidth(400);
   newWindow.setHeight(300);
   new();

First, we need to get the current window we want to work with, from which we are going to open the new window. This window will become the new window’s parent.

The new window is created with the .createWindow() method. The parameter is an optional parameter, but can be either a url, or an object containing the parameters for the new window. The url can be either an external url, which is signified by using http:// in the url, or else it can be a url pointing to an internal location in the application, which is prefixed by app:// and then the path to the html page to display.

Next we set a few attributes of the window. There is large amount of attributes that can be changed, which can be found in the documentation.

The last step now is to actually open the window, which is done with new().

Closing a window is very easy, and all it entails is calling newWindow.close().

Useful properties of Titanium.UI are Titanium.UI.mainWindow which is a reference to the main application reference, andTitanium.UI.windows, which is a list of all the windows in the application. The first element in the list (element 0) is the main window, and all user windows are then after that, ie. from 1 upwards. As an example, getting the width of the first window created by the application looks as follows:

   Titanium.UI.windows[1].getWidth();

The parent window can also be accessed very easily from the child window using the getParent() method, which returns a reference to the parent window object. For example, to get the title of the parent window we can write:

   newWindow.getParent().getTitle();

The UserWindow object makes it easy to work with almost any aspect of a window, and the full listing of available methods can be found at the Titanium API Documentation.

Share