views:

29

answers:

1

Hi there, this issue is kinda strange, and happens only in Firefox (v. 3.6.6 but also in older versions of 3.6). The best way to explain it is to describe the scenario, so.. here it is:

  1. I have two HTML pages: Page-A & Page-B. Page-A contains an iframe element, which its source points to Page-B.
  2. Page-B contains a JavaScript function: foo. for the sake of this example, this function only pops-up an alert.
  3. when Page-A is loaded for the first time, i'm able to get the iframe and execute the

JavaScript function like this:

window.frames["frameName"].foo();

Until now looks normal. but, when I dynamically remove the iframe from Page-A, and then dynamically adds it to the page, this is what happens:

** i can get the instance of iframe: window.frames["frameName"]

** when i try to execute the foo() function, i get an error that it is undefined.

This issue happens ONLY in Firefox. Testes in: IE 7/8, Chrome & Safari - works fine.

Any idea why this is happening? Any idea how to work this out?

A: 

Try accessing it using window.frames["frameName"].contentWindow.foo();

Sean Kinsey
using the contentWindow doesn't expose the JavaScript code, so it is not working in all browsers.
Actually it does. I'm guessing there is something else going on. You should show us the code where you add and remove the frame.
Sean Kinsey
OK, so i partially take it back.to make it work properly in ALL browsers, i needed to call it this way:document.getElementById("frameName").contentWindow.foo();calling using window.frames, simply doesn't work the same in Firefox.Thanks :)