Find element inside an iframe (external domain)

2019-06-11 11:06发布

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] ){ ... }

标签: jquery iframe
2条回答
不美不萌又怎样
2楼-- · 2019-06-11 11:25

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.

查看更多
▲ chillily
3楼-- · 2019-06-11 11:49

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

查看更多
登录 后发表回答