我有以下结构.
<div>
<p>Hello World !!</p>
</div>
<iframe id="myiframe" src='myiframeContent.html'></iframe>
Run Code Online (Sandbox Code Playgroud)
我有以下JavaScript变量content:
var s ="<html><head></head><body><div>Test_Div</div></body></html>";
Run Code Online (Sandbox Code Playgroud)
如何使用myiframe带变量的id更改iframe的内容s?
我试过了:
$("#myiframe").html(s);
Run Code Online (Sandbox Code Playgroud)
这给了我非常不寻常的回报,它将当前页面的所有内容更改为VAR S
Ex:样式,背景等.
如何使用包含HTML?的变量设置iframe的内容?
更新#1
:变量的内容s如下 - >
<html>
<head>
<title>{page_name}</title>
<meta name="keywords" content="{page_meta_tags}" />
<script src="/1.js"></script>
<script src="/2.js"></script>
<style>
h2{
color:red;}
h1{
color:red;}
body{
background-color:#f0eded;
color:74f503;
font-family:Verdana, Geneva, sans-serif;
background:url({getUrl});}
</style>
</head>
<body>
yahoo
<div style="float:right">{pagecomment}</div>
<div id="blogstart" style="">
<h1>My Blog</h1>
{nextPrevPagination}
{blog}
{nextPrevPagination}
</div>
<p>My Page Name : {page_name}</p><br/>
<p>Name of …Run Code Online (Sandbox Code Playgroud) 有没有人知道如何从IFRAME中获取HTML我已尝试过几种不同的方法:
document.getElementById('iframe01').contentDocument.body.innerHTML
document.frames['iframe01'].document.body.innerHTML
document.getElementById('iframe01').contentWindow.document.body.innerHTML
Run Code Online (Sandbox Code Playgroud)
等等
正如在这篇文章中所回答的那样,我正在尝试使用以下内容设置Iframe的内容:
document.getElementById("iframe").contentDocument.write("Test123");
Run Code Online (Sandbox Code Playgroud)
问题是即使一切似乎都有效(Iframe显示Test123),浏览器也不会停止加载.实际上,在Firefox的标签中,它与旋转器一起写成"正在连接......",表示它仍在加载.
为什么会这样?是否有更好的解决方案来设置Iframe的内容?