How to Check whether window property exists

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

Hey ,

I have the following code

Titanium.UI.createWindow({ url:'somenewcode.js', title:'your new window', oldWin:Ti.currentWindow // this gets you a pointer });

I want to check whether the oldWin exists in the window created.

I used this

if(Ti.UI.currentWindow.oldWin) { Ti.UI.currentWindow.oldWin.close(); }

but shows error. How can I check whether the oldWin exists

2 Answers

Accepted Answer

Hi Rebin

Fix this error and try again, if you still have a problem - report back.

Change this

Titanium.UI.createWindow({
  url:'somenewcode.js', 
  title:'your new window', 
  oldWin:Ti.currentWindow // this gets you a pointer
});
To this
Titanium.UI.createWindow({
  url:'somenewcode.js', 
  title:'your new window', 
  oldWin:Ti.UI.currentWindow // this gets you a pointer
});
Specific line
oldWin:Ti.UI.currentWindow // this gets you a pointer

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
5 Comments
  • I changed it. But I am still not able to check Message: Uncaught TypeError: Cannot read property 'oldWin' of undefined [ERROR][TiJSError( 290)] (main) [1,1743339] - Source: if(Ti.UI.currentWindow.oldWin.oldWin.oldWin){ [ERROR][V8Exception( 290)] Exception occurred at main_windows/appointmentDetails.js:465: Uncaught TypeError: Cannot read property 'oldWin' of undefined

    — commented 10 months ago by Rebin Joseph

  • Then it may be the scope of your app as you have used the url property, which is no longer encouraged. My tests are showing a custom property using the same name as yours is perfectly accessible when not using the url property.

    Titanium.UI.createWindow({
      url:'somenewcode.js',  // this one
    ...
    });

    — commented 10 months ago by Malcolm Hollingsworth

  • Sorry. I am not clear. Can you please explain

    — commented 10 months ago by Rebin Joseph

  • Show 2 more comments

Hi Rebin,

What is Ti.UI.currentWindow here - Is there any window that you created before creating this window? Can you please provide the complete code?

As far as I understand, this won't work because you are creating new window using url property which creates a new execution context where your previous variables/objects are not accessible.

Please read this post - (http://developer.appcelerator.com/blog/2010/08/execution-contexts.html)

Your Answer

Think you can help? Login to answer this question!