Find element inside an iframe (external domain)

2019-06-11 11:26发布

问题:

Is there any way to access elements loaded inside an iframe?

I'm trying this but doesn't seem to work:

if($('#cboxLoadedContent iframe').contents().find('#customer-login')[0] ){ ... }

回答1:

If the content of the iframe is provided by another domain, the only way you can see its content from your page is that this content is given with appropriate CORS headers.

This is a protection scheme known as Same Origin Policy.

Note that there is also the solution to let the browser see only one domain, by using a proxy.



回答2:

It worked, I hd opened the file locally (file://) whereas the content was loaded with http:// protocol.



标签: jquery iframe