Search code examples
titaniumappcelerator

How to pop to the parent window in a tab?


I am trying to replace the default Back button to a custom image button in a Titanium iOS project.

I am opening several windows in a tab with the following code:

currentTab.open(childWindow);

How do I "pop" back to the previous (parent) window?

I tried the following:

childWindow.close();

and:

currentTab.close(childWindow);

But both don't work. What am I doing wrong?


Solution

  • Andrew's answer helped and I solved the problem with win.close() function call.

    The reason it was giving the following error:

    Undefined is not a variable.

    was because I was trying to access the window variable with a wrong reference.

    this.backButton.addEventListener("click", function() {
     this.win.close();
    });
    

    this.win was the variable for the child window, and stupidly I used the same inside the backButton event listener, where this was recognized as the callback function and it gave me the above error.

    Just changing it to the following helped.

    _this = this;
    this.backButton.addEventListener("click", function() {
     _this.win.close();
    });