Take the 2-minute tour ×

I have a method inside of a MooTools class that I want to access after uploading a file with AJAX (iFrame). The Javascript that the iFrame page runs when it loads should call the method of the Class, but I am unable to access it using anything like: Class name: Main var class was initialized in: myMain

parent.window.myMain.myMethod parent.window.Main.myMethod

Is this even possible? If it is how do I do this?

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

The syntax I prefer:

var MyClass = new Class({

  /* list regular non-static methods her as usual */


MyClass.staticMethod = function()
   /* body of static function */

The advantages you have are:

  • You can call the static method via MyClass.staticMethod() inside and outside of your class
  • It is not possible to accidentally access the this-pointer in the static method as it is not available

To access the static method in an inner frame use can window.parent.MyClass.staticMethod();

share|improve this answer
Is it possible to access from staticMethod to common methods defined in new Class(...)? i.e.: ` MyClass.staticMethod = function(){ this.privateMethod()}; ` –  Martin Borthiry Jul 27 '11 at 13:18
No, this isn't possible, see the second point of my answer. Static methods can only access other static methods. If you need to access this create a regular method. –  sebasgo Jul 29 '11 at 9:06
add comment

This works for me (iframes too).

In main window.

var T=new MyClass();

In Iframe (which loads after T was initialized!)

share|improve this answer
I just keep getting "window.parent.myMain undefined" –  trobrock Jul 24 '09 at 15:57
add comment

Just figured it out. On the iFrame page, I need to use:


Might not be the proper way of accessing it, but it works.

share|improve this answer
add comment

Your Answer


