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.

谢谢

推荐答案

你不能.javascript无法读取跨站点内容.没有哪个主流浏览器会允许你这么做.很抱歉,这是一个设计缺陷,你应该放弃这个 idea .

EDIT

请注意,如果您对加载到IFRAME中的网站具有编辑访问权限,则可以使用postMessage(另请参阅browser compatibility)

Jquery相关问答推荐

如何定位 prism.js 脚本中包含的代码?

如何在没有实体框架的情况下在 ASP.NET 上使用 ajax 和 jquery 从列表创建数据表

jQuery .val() 和 .attr('value') 有什么区别?

为什么 .join() 不能与函数参数一起使用?

bootstrap 模式中的自动完成问题

$.post 和 $.ajax 之间的区别?

AngularJS 中的 ScrollTo 函数

如何在 jQuery Select 器中定义 css :hover 状态?

在 select2 中使用 AJAX 进行标记

jQuery从下拉列表中删除一个选项,给定选项的文本/值

使用 jQuery 的并行异步 Ajax 请求

jquery - 单击事件不适用于动态创建的按钮

javascript中的描述关键字

如何检测是否安装了 Flash,如果没有,显示一个隐藏的 div 通知用户?

好处和.在本地托管 jQuery 的trap

无法更新数据属性值

如何在按键事件后获取 jQuery .val()?

jQuery select2 获取 Select 标签的值?

使用中键触发 onclick 事件

如何在 DOM 中移动 iFrame 而不会丢失其状态?