views:

132

answers:

2

Hi all,
Here's the situation.

function scrollLog(line) { // Assume Firefox
    // alert("weird");
    frames['log'].find(line);
};

Here's a function I call when the document is ready. The code as written does not always fire . However, uncomment the alert line, and after the alert is fired, the find function always fires. Any ideas?

EDIT: Could this possibly be due to a load() issue where the timing of the loading of the iframe is not complete all the time? (These are pretty big log files)

Thanks,
Michael

+1  A: 

I think the issue might be that the main document dom could be loaded before the iframe's document DOM is loaded.

Have you tried basing it on the frames element?

$(frames['log']).ready( function () {});
MacAnthony
Yea, that's what I was thinking right after I posted -- gonna quickly try it.
Michael
Didn't work. Trying some other ways
Michael
Thanks for your suggestion, marcgg's "onload" syntax turned out to work.
Michael
+2  A: 

Often adding an alert will do funky stuff when javascript tries to communicate with something else. I experienced this with flash, when putting alerts would leave time for the flash to load and it would work. Removing the alert would break everything.

Here I'd say since you put an alert it give time to the frame to load and therefore you're able to access it. When you don't have an alert, it might not be loaded completely. Tries to check if the frame is loaded before accessing it.

marcgg
What's the syntax for checking if the frame is loaded?
Michael
You could do iframe.onload = function(){} I guess
marcgg
Thanks, that did it
Michael
glad I could help
marcgg
There's nothing funky about alert. DOM/resource dependent code *sometimes* works better when you pepper your code with alerts because it blocks execution until you dismiss it, which, of course, allows for more time to load the DOM/resource you are working with.
Justin Johnson
That's what I was saying, sorry if I wasn't clearer. When I say funky, it's because it makes everything really hard to figure out and debug when you're not aware of this.
marcgg