How to call javascript function in top frame?

It seems very simple, but how can I call the javascript function defined in the top level html from the child frame?

top html doc - 1st level frame - 2nd level frame 

my top html doc has a testFn () function. In the 2nd level frame, I have a button with onclick="top.testFn();" but this does not call testFn (). In Firebug, if I use a clock to execute top.testFn(); , he says TypeError: testFn () is not a function.

If all this just works - in this case, is it a problem with my documents or is there another way to call functions in a top-level window?

+6
javascript frames
source share
3 answers

Your code looks correct. If he says testFn() is not a function , then perhaps this is not so. Have you tried setting onload="testFn();" in <BODY> your top frame to make sure this works?

There may be some JavaScript error that leads to the creation of code where the testFn function testFn to complete successfully.

+4
source share

You tried calling it like this:

OnClick = "parent.parent.testFn ();"

I assume that you have a second frame inside the first frame.

+2
source share

Actually, this is exactly how you do it.

The trick has no syntax error elsewhere in javascript on this top level html page :-)

0
source share

All Articles