Forum Moderators: open

Message Too Old, No Replies

Calling a function in another document

which is included using <object>

         

adb64

2:28 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



On a page (lets call it PageA) I include another HTML document (PageB) using <object> and PageB displays something using javascript.
What I want is to call a javascript function in PageB from PageA.
So in PageA I have something like:

<object name="pageb" width="600" height="500" type="text/html" data="PageB.html"></object>
<a href="#" onclick="pageb.SomeFunction(); return false;">Do Something</a>

I know the code above is not correct but it gives an idea of what I want to do.

How can I call a function defined in PageB from PageA?

I already tried using 'id' instead of 'name' and using getelementbyid() and such, but with no result so far.

Thanks,
Arjan

Trace

4:06 pm on Nov 3, 2006 (gmt 0)

10+ Year Member



I'm pretty sure, without actually trying it myself, that you can call the function like this:

onclick="parent.FunctionName()"

Trace

4:16 pm on Nov 3, 2006 (gmt 0)

10+ Year Member



Oh wait, I read it backwards - you want the opposite.

I tried this real quick...

1.html
<a onclick="document.frmThingy.something();">click</a>
<iframe src="2.html" name="frmThingy"></iframe>

2.html
<script>
function something(){
alert(1);
}
</script>