user1675891
user1675891

Reputation:

How to identify which IFRAME is which?

How to refer to a component inside an IFRAME is showed in this reply. It works under the assumption that there's only one IFRAME (or that we are certain that the zero-th will suffice). However, I wonder how to identify the actual IFRAME I'd like to poke.

I need the syntax for changing:

window.frames[0].document. + my stuff

into something like:

window.frames["theIdOfMyIFrame"].document. + my stuff

but I can't get it right.

Upvotes: 0

Views: 279

Answers (3)

Konrad Viltersten
Konrad Viltersten

Reputation: 39118

  1. I would avoid using window.frames. (Might be due to the lack of experience with them.)
  2. When a reply on the net is on form something[0], be cautious. Bad coding style, probably.
  3. The reference to your theIdOfMyIFrame should be used.
  4. The inner document is right under contentDocument.

You can refer to the embedded components like this.

document.getElementById("theIdOfMyIFrame")
  .contentDocument.getElementById("controlIdInTheembeddedPage")
    .value = "Christophe has eyes for details!";

Upvotes: 0

Nightly Coder
Nightly Coder

Reputation: 121

I dealt with this problem earlier.

If you show the response of a cross-site request in an iframe, the new browsers are denying the access to this iframe, because of the same-origin policy or cross-site scripting/request prohibition.
For more information see here: IFrame Permission Denied

If you want to dynamically add content, this solution might help you: Add Dynamic Content

Best regards

Upvotes: 1

user149341
user149341

Reputation:

Use document.getElementById instead of the nasty deprecated window.frames property:

document.getElementById("theIdOfMyIFrame").contentDocument ...

Upvotes: 0

Related Questions