如何通过DOM / Javascript访问外部iframe的内容? [英] How can you access an external iframe's contents via the DOM/Javascript?

查看:110
本文介绍了如何通过DOM / Javascript访问外部iframe的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面:

<html>
    <head></head>
    <body>
        <iframe src="local.html"></iframe>
        <iframe src="http://www.google.com"></iframe>
    </body>
</html>

我已经使用DOM访问第一个iframe作为测试(node.documentWindow),但是我尝试类似的外部iframe Firebug报告访问被拒绝。

I've used the DOM to access the first iframe as a test (node.documentWindow) but when I try similar on the external iframe Firebug reports that access is denied.

我怀疑这是为了XSS保护,但是是否有一个安全的方式导入节点我可以从外部页面中获取元素吗?有没有办法探索文件呈现或什么?

I suspect this is for XSS protection, but is there a "safe" way to import the node so I can grab an element from that external page? Is there a way to explore the "document as rendered" or something?

谢谢!

推荐答案

不。跨域安全性防止这种情况。唯一的办法是如果周围的页面和iframe在同一个域上的不同子域上。在这种情况下,您可以使用 document.domain

Nope. Cross domain security prevents this. The only way around is if the surrounding page, and the iframe, are on different subdomains on the same domain. In that case, you can use document.domain.

这几乎是一个给定的。如果不是这样,想像一下安全隐患。您可以构建一个包含用户家庭银行页面的iframe,并使用 keydown 获取密码。有很多可能性被滥用。

This is pretty much a given. Imagine the security implications if this were not the case. You could build an iframe containing a user's home banking page, and grab their password using keydown, for example. There's tons of possibilities of misuse.

这篇关于如何通过DOM / Javascript访问外部iframe的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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