views:

30

answers:

1

Hi,

I have an iframe created in Javascript with some function f():

var iframe = document.createElement("iframe");
$(iframe).attr({
  width: 0,
  height: 0,
  frameborder: 0,
  src: this.options.url,
  name: id,
  id: id
});

document.body.appendChild(iframe);

iframe.contentWindow.f = function(data) {
 alert("test");
};

Document loaded in this iframe should call function f():

<script ...>f();</script>

And this works perfectly in Firefox but Opera tells, f() is undefined.

Is there any solution?

Adrian.

+1  A: 

It's a good change there is a race condition so that the document in the iframe has finished loading before you set the function. It probably would be better to have the iframe document call a function in the parent document instead.

RoToRa
You're right. Probably this is the reason. Actually I call parent iframe function and it works. This is not the best solution for me, but good to know, why self.f() won't work in Opera. Thanx!
Adrian