如何加载iframe后身体? [英] How get iframe body after load?

查看:135
本文介绍了如何加载iframe后身体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在iframe加载后获取iframe主体

I need obtain the iframe body after iframe load

推荐答案

document.getElementById('frame' ).contentDocument.body 将使用纯JavaScript为您提供,假设iframe的ID为 frame 。在jQuery中,这将是 $('#frame')。contents()。find('body')

document.getElementById('frame').contentDocument.body will give you it in pure JavaScript, assuming that the iframe's ID is frame. In jQuery, that would be $('#frame').contents().find('body').

请注意,由于同源策略,只有iframe和周围网页的网址具有完全相同的主机名和端口号时才会生效。

Note that because of the same-origin policy, this will only work if the iframe and the surrounding pages' URLs have exactly the same hostname and port number.

修改:您评论说在尝试此代码时出现拒绝访问错误。同源政策是这种情况发生的原因。优秀的浏览器安全手册有有关此信息的信息。仔细阅读该网页将表明有办法突破,但除非您出于安全和隐私原因控制所附网站,否则无法实现这一目标。

You commented that you get an "Access denied" error when you tried this code. The same-origin policy is why this happens. The excellent Browser Security Handbook has information about this. A close reading of that web page will suggest that there are ways to break through, though this is not possible unless you control the enclosed site because of security and privacy reasons.

这篇关于如何加载iframe后身体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆