Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

(我想使用jQuery在iframe中操纵HTML。)

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:

(我认为我可以通过将jQuery函数的上下文设置为iframe的文档来做到这一点,例如:)

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

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.

(一点检查显示出,除非等待iframe加载一会儿,否则frames['nameOfMyIframe']中的变量是undefined 。)

However, when the iframe loads the variables are not accessible (I get permission denied -type errors).

(但是,在iframe加载时,变量不可访问(我收到permission denied -类型错误)。)

Does anyone know of a work-around to this?

(有人知道解决方法吗?)

  ask by rz. translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
221 views
Welcome To Ask or Share your Answers For Others

1 Answer

If the <iframe> is from the same domain, the elements are easily accessible as

(如果<iframe>来自相同的域,则可以很容易地访问元素)

$("#iFrame").contents().find("#someDiv").removeClass("hidden");

Reference

(参考)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...