Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding an iframe within another iframe?

I have the id of the parent, but not the child iframe.

Is there a way to return the iframe within the parent iframe?

Or, all iframes within a particular iframe?

Using jQuery to find element with $('iframe') doesn't seem to work.

like image 457
Sara Chipps Avatar asked May 18 '26 23:05

Sara Chipps


1 Answers

If the iframe's src attribute has the same domain, protocol and port, you are set. If not, you can't do anything because of Same Origin Policy.

Assuming you are not violating the policy...

Regular JavaScript

var iframe = document.getElementsByTagName('iframe')[0],
    iframeDocument = iframe.contentWindow || iframe.contentDocument,
    internalIframes = iframeDocument.getElementsByTagName('iframe');

You need to use the || short circuit evaluation exploit as IE is different.

jQuery

var internalIframes = $('iframe:first').contents().find('iframe');
like image 52
alex Avatar answered May 20 '26 14:05

alex