简体   繁体   English

使用jQuery在iframe中查找元素的高度

[英]Finding height of an element inside iframe using jquery

I just tried a selector, something like this 我刚刚尝试了一个选择器,像这样

$('#message_type_popup').contents().find('#bb-main-content').height();

and it's resulting 结果

Error: Permission denied for <file://> to get property HTMLDocument.ownerDocument from <http://www.sample.com>.

I just tried it locally. 我只是在本地尝试过。 It works if I'm loading the iframe from same domain. 如果我要从同一个域加载iframe,它会起作用。

如果iframe不是来自同一域,则由于浏览器具有相同的来源政策 ,因此您将无法使用javascript访问其内容

This is to prevent cross-site scripting attacks (XSS). 这是为了防止跨站点脚本攻击(XSS)。 Content of the iframe should be originating from the same domain in order for you to be able to manipulate it through JavaScript iframe的内容应源自同一域,以便您能够通过JavaScript对其进行操作

Some interesting reading on the topic: http://pipwerks.com/2008/11/30/iframes-and-cross-domain-security-part-2/ 关于该主题的一些有趣的阅读: http : //pipwerks.com/2008/11/30/iframes-and-cross-domain-security-part-2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM