How to choose iframe from yourself using jquery

I need to select an iframe with a jquery query inside the same iframe. However, I do not want to give the iframe a unique identifier and use

$('#'+self.name,top.document)

(which I saw somewhere). Is there any relative way to do this (something with $ (this) and intersection?!?)

All on one server, no xss.

+3
source share
2 answers

If you only have one iFrame on your site, this is easy. Just use this selector.

 $('iframe', parent.document)

, . iFrame , iframes , iframe . , , , , URL- iframe, , , iframe. iframe, , .

 // iframe with MyClass class
 $('iframe.MyClass', parent.document);

 // iframe with MyId id
 $('iframe#MyId', parent.document);
 // even better since id is unique
 $('#MyId', parent.document);

 // iframe with myname name
 $('iframe[name=myname]', parent.document);

 // iframe with specific src
 $('iframe[src=/path/to/iframe/source]', parent.document);

 // second iframe (index is starting from 0)
 $('iframe:eq(1)', parent.document); 
+25

iframe, :

second iframe (index is starting from 0)
$('iframe:eq(1)', parent.document);
+2

Source: https://habr.com/ru/post/1714193/


All Articles