如何阅读跨域iframe内容? [英] How to read cross- domain iframe content?
问题描述
嗨!
我正在嵌入另一个域中具有src ="的iframe.
例如:我的页面是www.abc.com/Default.aspx,而iframe是
Hi!
I am embedding an iframe which has src ="" from another domain.
For example: my page is www.abc.com/Default.aspx, and the iframe
<iframe id="myFrame" src="www.xyz.com/search.aspx"></iframe>
.
我要做的就是在加载iframe时浏览DOM,选择一个特定的div,然后更改该div的内容,例如:
.
All that I want to do is when the iframe loaded, I will navigate throught the DOM and select a specific div and change the content of that div like:
$(function(){
$("#myFrame").load(function(){
var iBody = $("#myFrame").contents().find("body");
var iDiv = iBody.find("#divID");
/*code to change the div content*/
});
});
但是,我无法访问iframe DOM,因为我的iframe是跨域iframe,并且出于安全原因而拒绝了该访问.
谁能给我解决方案?我正在为项目使用.NET C#.
However, I cannot access the iframe DOM since my iframe is crossed- domain iframe, and the access is denied for security reason.
Can anyone give me a solution? I am using .NET C# for my project.
推荐答案
(函数(){
(" ).load( var iBody =
("#myFrame").load(function(){ var iBody =
(" ).contents().find(" ); var iDiv = iBody.find(" ); /* 更改div内容的代码*/ }); });
("#myFrame").contents().find("body"); var iDiv = iBody.find("#divID"); /*code to change the div content*/ }); });
但是,我无法访问iframe DOM,因为我的iframe是跨域iframe,并且出于安全原因而拒绝了该访问.
谁能给我解决方案?我正在为项目使用.NET C#.
However, I cannot access the iframe DOM since my iframe is crossed- domain iframe, and the access is denied for security reason.
Can anyone give me a solution? I am using .NET C# for my project.
这篇关于如何阅读跨域iframe内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!