我正在使用托管 CMS,它在另一个 iFrame 中呈现一个 iFrame。这些 iFrame 是从同一域加载的,但由于这是托管 CMS,我无法直接访问这些 iFrame。是否可以使用 jQuery 将 HTML 内容插入到body
iFrame 的标签,id 为re_contentIframe
?
以下是代码在我的网站上的呈现方式:
<div class="editor">
<iframe id="editorf" frameborder="0" src="/ForumEditor.aspx?ForumID=2221&TopicID=-1&NoTemplate=False&Internal=False" style="display: inline;">
<html>
<head></head>
<body>
<!-- CODE -->
<iframe id="re_contentIframe" frameborder="0" src="javascript:'<html></html>';">
<html>
<head></head>
<body> <!-- THIS IS WHAT I WANT TO TARGET --> </body>
</html>
</iframe>
<!-- CODE -->
</body>
</html>
</iframe>
</div>
我尝试使用以下代码,但此代码没有任何反应(包括没有错误):
$(function() {
$( "#test" ).click(function() {
$("#re_contentIframe").contents().find("body").html("<p>new HTML content goes here</p>");
});
});
问题是您正在尝试访问嵌套框架。
The #re_contentIframe
框架嵌套在#editorf
,随后嵌套在您的文档中。
Try:
$('#re_contentIframe').contents().find('body').find('#editorf').contents()
Fiddle: http://jsfiddle.net/8VP4y/3/ http://jsfiddle.net/8VP4y/3/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)