Access the MooTools class method from outside the class

I have a method inside the MooTools class that I want to get after loading a file using AJAX (iFrame). The javascript that starts when iFrame loads should call the class method, but I cannot access it using something like: Class name: Main var class was initialized to: myMain

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

Is it possible? If so, can I do this?

+4
source share
3 answers

The syntax I prefer is:

var MyClass = new Class({ /* list regular non-static methods her as usual */ }); MyClass.staticMethod = function() { /* body of static function */ }; 

Benefits you have:

  • You can call the static method via MyClass.staticMethod() inside and outside your class
  • You cannot accidentally access this pointer in a static method because it is not available.

To access the static method in the internal frame, use window.parent.MyClass.staticMethod();

+10
source

This works for me (iframes too).

In the main window.

 var T=new MyClass(); 

In an Iframe (which loads after initializing T!)

 window.parent.T.anyMethodOfMyClass() 
0
source

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

window.parent.Main.prototype.myMethod ();

There may not be a suitable way to access it, but it works.

0
source

All Articles