Crista23
Crista23

Reputation: 3243

Mozila Firefox - setting the content of an iframe isn't working

I am having a hard time trying to set the content of an iframe using Firefox browser. In my code I have a label for which I set the content in code-behind on page load event

<asp:Label ID="lbnAdd" runat="server" />
lbnAdd.Text = "<iframe style=\"display:none;\" id=\"myIframe\" frameborder=\"0\" scrolling=\"no\" height=\"380px\" width=\"745px\"></iframe>";

ClientScript.RegisterClientScriptBlock(this.GetType(), "Test", "<script type='text/javascript'>function MyTest() { document.getElementById('myIframe').style.display=\"block\"; frames['myIframe'].location.href = 'myURL'; } </script>");

I must say that this works perfectly in IE8, Chrome and Opera, but not in Mozilla. Javascript alerts me that frames['myIframe'] is undefined in Firefox, while it is object in the rest of the browsers. What could be the explanation for this, any suggestions?

Thank you!

Upvotes: 0

Views: 227

Answers (1)

mplungjan
mplungjan

Reputation: 177885

frames["myIframe"].location expects a name="myIframe"

You only have an ID.

If you also give it a name or use document.getElementById("myIframe").src=... it should work

Upvotes: 1

Related Questions