gpt4 book ai didi

javascript - 使用 jQuery 将 HTML 插入到 iFrame 正文标记中

转载 作者:搜寻专家 更新时间:2023-10-31 08:19:14 26 4
gpt4 key购买 nike

我正在使用在另一个 iFrame 中呈现 iFrame 的托管 CMS。这些 iFrame 是从同一个域加载的,但由于这是一个托管 CMS,我无法直接访问这些 iFrame。是否可以使用 jQuery 将 HTML 内容插入到 ID 为 re_contentIframe 的 iFrame 的 body 标记中?

以下是代码在我的网站上的呈现方式:

<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>");
});
});

最佳答案

问题是您正在尝试访问嵌套框架。

#re_contentIframe 框架嵌套在 #editorf 中,随后嵌套在您的文档中。

尝试:

$('#re_contentIframe').contents().find('body').find('#editorf').contents()

fiddle :http://jsfiddle.net/8VP4y/3/

关于javascript - 使用 jQuery 将 HTML 插入到 iFrame 正文标记中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com