获取跨域iframe的DOM内容 [英] Get DOM content of cross-domain iframe

查看:1030
本文介绍了获取跨域iframe的DOM内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个跨网站的iframe。我想读取iframe的DOM,我相信这是可能的,因为使用检查器,我甚至可以修改iframe的DOM。我尝试阅读它的每一种方式,但是,我遇到了相同的原产地政策。我想要的是从iframe中加载的本地DOM中的内容。我认为它就像 $(document.body).find('iframe')。html()一样简单,但是它返回空字符串。

I have an iframe for a cross-domain site. I want to read the DOM of the iframe, which I believed was possible because using the inspector, I can even modify the DOM of an iframe. Every way I attempt to read it, however, I run into the same origin policy. All I want, is the content loaded in my local DOM, from the iframe. I thought it would be as simple as $(document.body).find('iframe').html(), but that's returning the empty string.

我真的希望有一种方法可以做到这一点,因为过去几天我一直在做的工作已经被预测可以实现。

I really hope there's a way to do this since the work I've been doing for the last several days has been predicated on this being do-able.

谢谢

Thanks

推荐答案

你不能。 XSS保护。跨站点内容无法通过JavaScript读取。没有主要的浏览器会允许你。我很抱歉,但这是一个设计缺陷,你应该放弃这个想法。

You can't. XSS protection. Cross site contents can not be read by javascript. No major browser will allow you that. I'm sorry, but this is a design flaw, you should drop the idea.

编辑

请注意,如果您已编辑访问加载到iframe的网站,则可以使用 postMessage (另请参阅浏览器兼容性

Note that if you have editing access to the website loaded into the iframe, you can use postMessage (also see the browser compatibility)

这篇关于获取跨域iframe的DOM内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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