jQuery / JavaScript:访问iframe的内容 [英] jQuery/JavaScript: accessing contents of an iframe

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

问题描述

我想使用jQuery在iframe中操作HTML。

I would like to manipulate the HTML inside an iframe using jQuery.

我以为我可以通过将jQuery函数的上下文设置为是iframe的文档,例如:

I thought I'd be able to do this by setting the context of the jQuery function to be the document of the iframe, something like:

$(function(){ //document ready
    $('some selector', frames['nameOfMyIframe'].document).doStuff()
});

然而这似乎不起作用。一点检查告诉我, frames ['nameOfMyIframe'] 中的变量是 undefined 除非我等待一段时间要加载的iframe。但是,当iframe加载时,变量无法访问(我得到权限被拒绝 -type错误)。

However this doesn't seem to work. A bit of inspection shows me that the variables in frames['nameOfMyIframe'] are undefined unless I wait a while for the iframe to load. However, when the iframe loads the variables are not accessible (I get permission denied-type errors).

有人知道这方面的解决方法吗?

Does anyone know of a work-around to this?

推荐答案

我认为你所做的是受同源政策。这应该是您获得权限被拒绝类型错误的原因。

I think what you are doing is subject to the same origin policy. This should be the reason why you are getting permission denied type errors.

这篇关于jQuery / JavaScript:访问iframe的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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