Clarification: The parent frame is Page X, the child frame resides within page X.
The issue is the slow behavior and never hitting the section of code that clears the interval.
I have a parent and chilframe. An object is created in the parent then I used setTimeout() in the childframe to call the parent object to add itself to an internal collection within the parent object.
The code doesn’t seem to behave as intended with really slow response from the browser. Any thoughts on the issue?
Parent frame
<script type="text/javascript">
var Cert = new Parent();
</script>
Child frame
<script type="text/javascript">
var c;
var id = setInterval("Create()", 1000);
function Create()
{
if (parent.Cert != null && parent.Cert != undefined)
{
c = new Child(parent.Cert, 1, null);
clearInterval(id);
}
}
</script>
Don’t pass a string to
setTimeout/Interval. Pass it a function reference instead!From the code you’ve given here,
parentiswindow. Is this what you intend? There seems to be some relevant code missing here…As for the slowdown, perhaps the function interval is too short, or it is never being satisfied? There could also be an error in the constructor for the
Childclass, which would make it so theclearIntervalline won’t ever be called. You could consider putting a limiter out there, or wrapping your instantiation in atry...catchblock, or moving theclearIntervalstatement above the line where you’re creating your object.Or, do all of those things: