dude dude - 1 year ago 80
HTML Question

Get parent iframe element by an element located within an iframe

Assuming you have the following HTML:

<iframe src="..">
<!-- The following would be the content of the iframe -->
<span>I'm the node</span>

And you have a variable
containing the
element within that iframe. Your script context is the parent window.

How would you get the parent iframe element:

<iframe src="..."></iframe>

by this node?

In theory:

var iframe = iframeNode.myParentIframeElementInTheParentScope;

Answer Source

If your only reference to the iframe is a span in that iframe (= iframeNode), then

var iframe = iframeNode.ownerDocument.defaultView.frameElement;

will refer to the iframe element in the parent window.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download