472,143 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

call function in iframe

I have document with an iframe in it. I'm able to call a javascript
function in the main-document from the javascript inside the
iframe-document. I have difficulties to do the other way round, i.e. to
call a function in the iframe-document from javascript in the main-document.
TIA

Christian

Jul 20 '05 #1
5 94104

"Christian Radermacher" <ra***@inwind.it> schreef in bericht
news:C9*********************@news1.tin.it...
I have document with an iframe in it. I'm able to call a javascript
function in the main-document from the javascript inside the
iframe-document. I have difficulties to do the other way round, i.e. to
call a function in the iframe-document from javascript in the main-document.


The following works with IE, Opera 7 and Mozilla when both pages are hosted
on the same domain/environment:

d = document;
f = d.frames ? d.frames['frameName'] : d.getElementById('frameId');
p = f.document || f.contentWindow.document;

p.functionName();
JW

Jul 20 '05 #2


Christian Radermacher wrote:
I have document with an iframe in it. I'm able to call a javascript
function in the main-document from the javascript inside the
iframe-document. I have difficulties to do the other way round, i.e. to
call a function in the iframe-document from javascript in the
main-document.


Use
<iframe name="iframeName"
and then
if (window.frames.iframeName && window.frames.iframeName.functionName) {
window.frames.iframeName.functionName();
}


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3


Christian Radermacher wrote:
I have document with an iframe in it. I'm able to call a javascript
function in the main-document from the javascript inside the
iframe-document. I have difficulties to do the other way round, i.e. to
call a function in the iframe-document from javascript in the
main-document.


Use
<iframe name="iframeName"
and then
if (window.frames.iframeName && window.frames.iframeName.functionName) {
window.frames.iframeName.functionName();
}


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4
nec
I've got the same problem as Christian..

When i use the functioncall window.frames.contens.alerter('dsa') (in then
iFrame called contens, and the function called alerter) i get this message
in the FireFox Javascript Console:

Error: window.frames.contens has no properties

The script wors fine in IE (or rather: a variant of it) som the frame name
and fuction is right.

How was it solved?
Jul 23 '05 #5
Hi,

In article
<aa******************************@localhost.talkab outprogramming.com>, Nec
wrote:
When i use the functioncall window.frames.contens.alerter('dsa') (in then
iFrame called contens, and the function called alerter) i get this message
in the FireFox Javascript Console:

Error: window.frames.contens has no properties

The script wors fine in IE (or rather: a variant of it) som the frame name
and fuction is right.


The parent page of the IFrame needs to contain the functions called by a
page loaded into the IFrame.

I hope it helps,

Ranbir
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Adrian | last post: by
53 posts views Thread by souporpower | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.