Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

createWindow and onLoad

Hey all,

So, I'm trying to create a window and listen to its onload event, but, to no avail. This is how I'm creating/launching my window (w/ a correct url ;) :

var newAccountWin = Titanium.UI.getCurrentWindow().createWindow("url");
newAccountWin.setWidth(500);
newAccountWin.setHeight(550);
newAccountWin.open();

This works fine, but, my attempts to hook the onload events do not:

newAccountWin.onload=function(){alert("onload")}

-

newAccountWin.addEventListener("load",function(){alert("onload")},false)

-

Titanium.UI.windows[1].onload=function() {alert("load")}//windows[1] should be equal to newAccountWin

None, of the above work. Is this even possible? Am I overlooking something stupid? Do I need to do anything with getDOMWindow()? Any help would be greatly appreciated.

Thanks!

— asked June 11th 2010 by Matt Powell
  • createwindow
  • desktop
  • event
  • onload
0 Comments

4 Answers

  • Ah hah, use "page.load" instead of load (or Titanium.PAGE_LOAD):

    newAccountWin.addEventListener(Titanium.PAGE_LOAD,function() {
     alert("loaded")
    },false)
    

    Seems to fire twice, but, atleast we're making progress!

    — answered June 11th 2010 by Matt Powell
    permalink
    2 Comments
    • As James says, this is only for desktop apps.

      — commented April 5th 2011 by Joe iEntry
    • It's now called Titanium.PAGE_LOADED

      — commented December 30th 2011 by Emil Stenström
  • 'load' does not appear to be a valid event unless you are throwing it from somewhere else:

    http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object

    — answered June 11th 2010 by James Armstead
    permalink
    0 Comments
  • Nice! I'm creating a desktop app; didn't think to look in the mobile docs ;)

    But, ya, you're right… no load event :(

    Guess I'll have to go another route.

    Thanks!

    — answered June 11th 2010 by Matt Powell
    permalink
    0 Comments
  • Have you tried "focus"?

    newAccountWin.addEventListener("focus", function() { .... });
    
    — answered August 31st 2012 by Rafael Cardoso
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.