Creating a javascript object within an iFrame by accessing the parent window

90 Views Asked by At

I know that I can access any function in a parent window from an iFrame by saying window.parent.whateverFunctionItIs(); provided that the parent document does indeed contain a function named whateverFunctionItIs. The question is, how do I create such an object within an iFrame like I would normally create by using something like object1 = new ObjectMaker(); given that ObjectMaker exists in the parent document.

1

There are 1 best solutions below

0
HolyResistance On

The answer is,

object1 = new window.parent.ObjectMaker();

Possible mistake for beginners,

object1 = window.parent.new ObjectMaker(); // WRONG!