同一个域:如何使用jquery或javascript访问iframe内容
我在页面中创建了一个动态iframe,并在iframe中加载html内容,但使用jquery无法访问iframe中的html内容 根据网站上的结果,发现以下两种情况,但不适用于我的情况同一个域:如何使用jquery或javascript访问iframe内容,javascript,jquery,html,css,iframe,Javascript,Jquery,Html,Css,Iframe,我在页面中创建了一个动态iframe,并在iframe中加载html内容,但使用jquery无法访问iframe中的html内容 根据网站上的结果,发现以下两种情况,但不适用于我的情况 iframe的URL与我在src中使用的/testhtm.html相同,并正在加载它 iframe正在加载,因为在我触发事件后,当iframe加载时,我已发出警报 在控制台上尝试访问iframe时,浏览器中出现错误: 错误:访问属性“文档”的权限被拒绝 document.getElementById('TestF
document.getElementById('TestFrame').contentWindow.document.body.inne 正在尝试访问iframe中的我的div:
$("#testFrame").contents().find("#myDiv");
iframe代码:
var ifr = $('<iframe/>', {
id: 'testiframe',
name: 'genericFrame',
src: '/testhtml.html?' + serializeForm(params),
style: 'display: none',
load: function(){
alert('iframe loaded !');
}
});
$('#overlay').html(ifr); // Attaching it to overlay so that iframe loads in a lightbox
但使用jquery会引发错误:
var iBody = $("#testFrame").contents().find("body");
Error: Permission denied to access property 'document'
可能的副本。你检查过了吗?如果是,请更新您的问题,说明为什么不适合您的情况。您是否尝试阅读此内容?同样的问题在这里!!您不能像这样阅读iframe的内容。。您需要以另一种方式实现它,比如messagepasshow@DevendraSoni?你能用一个例子或链接解释一下吗?@GOK你到底想做什么?您还可以使用jQuery加载等
var iBody = $("#testFrame").contents().find("body");
Error: Permission denied to access property 'document'