sakthivelcs
12-31-2009, 12:14 PM
I have a set of Iframe created dynamicaly in a page. I have some JavaScript objects defined in main page as well as in the pages that is loaded in the iframes. I need to call function from main page to pages in iframe and vice versa. I want to use event- subscriber model .i.e. objects in the iframe will subscribe to the application events from the main page.
For this i have
In Main page
var mainModule = {};
mainModule.EventList =[];
mainPage.subscribeEvent = function(object, funName)
{
var eventObject = {};
eventObject.EventObj = evntObject;
eventObject.EventHandler = funName
mainPage.EventList.push(eventObject);
}
in the page that is loaded in the iframe i have
subModule = {};
subModule.prototype.init = function()
{
top.mainPage. subscribeEvent( this, this.appEventHandler );
}
subModule.prototype.appEventHandler = function()
{
// handler code.
}
When an application event occurs in the main page, i iterate through the array and call the subscriber's function by
var eventObject = eventArray[icount];
if (!eventObject.EventObj) return;
eventObject.EventHandler.apply(eventObject.EventObj, argArray);
This code generally works. The issues is when the iframe is destroyed, the reference to the subscriber's object and the function exists in the eventlist.So when application event occurs, I get the error "Can't execute code from a freed script" . Is there any method in javascript to check whether the object is valid.
For this i have
In Main page
var mainModule = {};
mainModule.EventList =[];
mainPage.subscribeEvent = function(object, funName)
{
var eventObject = {};
eventObject.EventObj = evntObject;
eventObject.EventHandler = funName
mainPage.EventList.push(eventObject);
}
in the page that is loaded in the iframe i have
subModule = {};
subModule.prototype.init = function()
{
top.mainPage. subscribeEvent( this, this.appEventHandler );
}
subModule.prototype.appEventHandler = function()
{
// handler code.
}
When an application event occurs in the main page, i iterate through the array and call the subscriber's function by
var eventObject = eventArray[icount];
if (!eventObject.EventObj) return;
eventObject.EventHandler.apply(eventObject.EventObj, argArray);
This code generally works. The issues is when the iframe is destroyed, the reference to the subscriber's object and the function exists in the eventlist.So when application event occurs, I get the error "Can't execute code from a freed script" . Is there any method in javascript to check whether the object is valid.