Javascript 使用jQuery将HTML插入iFrame主体标记中
我使用的是一个托管CMS,它在另一个iFrame中呈现一个iFrame。这些iFrame是从同一个域加载的,但由于这是一个托管CMS,我无法直接访问这些iFrame。是否可以使用jQuery将HTML内容插入id为Javascript 使用jQuery将HTML插入iFrame主体标记中,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我使用的是一个托管CMS,它在另一个iFrame中呈现一个iFrame。这些iFrame是从同一个域加载的,但由于这是一个托管CMS,我无法直接访问这些iFrame。是否可以使用jQuery将HTML内容插入id为re\u contentIframe的iFrame的body标记中 以下是代码在我的网站上的呈现方式: <div class="editor"> <iframe id="editorf" frameborder="0" src="/ForumEditor.asp
re\u 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>
我尝试使用以下代码,但此代码没有任何变化(包括没有错误):
$(函数(){
$(“#测试”)。单击(函数(){
$(“#re#u contentIframe”).contents().find(“body”).html(“新的html内容放在这里””;
});
});
尚未检查,可能会有帮助:
var frameObject = document.getElementById('editorf');
var frameContent = frameObject.contentDocument ||
frameObject.contentWindow.document;
var insideIframe = frameContent.getElementById('re_contentIframe');
var insideIframeContent = insideIframeObject.contentDocument ||
insideIframeObject.contentWindow.document;
var $body = $('body',insideIframeContent);
$body.html('<div>contentupdated</div>');
var frameObject=document.getElementById('editorf');
var frameContent=frameObject.contentDocument||
frameObject.contentWindow.document;
var insideIframe=frameContent.getElementById('re_contentIframe');
var insideIframeContent=insideIframeObject.contentDocument||
insideIframeObject.contentWindow.document;
var$body=$('body',insideIframeContent);
$body.html('contentupdated');
问题是您试图访问嵌套帧
#re#u contentIframe
框架嵌套在#editorf
中,该框架随后嵌套在文档中
尝试:
小提琴:可能是?@VijetaShetty的复制品-我不这么认为。这就是我找到我试过的代码的地方。如上所述,它不起作用,我不确定为什么。
var frameObject = document.getElementById('editorf');
var frameContent = frameObject.contentDocument ||
frameObject.contentWindow.document;
var insideIframe = frameContent.getElementById('re_contentIframe');
var insideIframeContent = insideIframeObject.contentDocument ||
insideIframeObject.contentWindow.document;
var $body = $('body',insideIframeContent);
$body.html('<div>contentupdated</div>');
$('#re_contentIframe').contents().find('body').find('#editorf').contents()