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

查看:26
本文介绍了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 加载时,变量不可访问(我收到 permission denied 类型的错误).

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天全站免登陆