我有以下结构.
<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插入其中吗?
换句话说,假设我有一个带id的空iframe,
如何在其中插入html?
我正在使用jquery,如果这更容易.
这是我的HTML:
<a>View it in your browser</a>
<div id="html">
<h1>Doggies</h1>
<p style="color:blue;">Kitties</p>
</div>
Run Code Online (Sandbox Code Playgroud)
如何使用JavaScript来使href我的链接点的属性base64编码的网页,其来源是innerHTML的div#html?
我基本上想要在这里完成相同的转换(选中base64复选框),但在JavaScript中除外.
我写了一个简单的React组件,它呈现了一个<iframe>:
export class Iframe extends React.component {
render() {
return <iframe src={ this.props.src } />;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图通过检查加载的内容src是否正确填充来测试它<iframe>.为了做到这一点,我尝试访问frame.contentWindow,但在用Enzyme安装后它总是返回undefined.
我试图<iframe>用Sinon 模拟内容FakeXMLHttpRequest:
server = sinon.fakeServer.create();
server.respondWith('GET', 'test', [200, { 'Content-Type': 'text/html' }, '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><body><div class="myClass">Amazing Unicorn</div></body></html>']);
container = mount(<Iframe src='test' />);
Run Code Online (Sandbox Code Playgroud)
并与<iframe src='data:text/html' >:
const src = 'data:text/html;charset=utf-8,<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><body><div class="myClass">Amazing Unicorn</div></body></html>';
container = mount(<Iframe src={ src } />);
Run Code Online (Sandbox Code Playgroud)
但在两种情况下用酶测试:
container = mount(<Iframe src='...' />); …Run Code Online (Sandbox Code Playgroud) 我有一个IFRAME应该填充JavaScript的内容.如果内容在服务器上,我所要做的就是:
function onIFrameFill() {
myIframe.location.href = "HelloWorld.html";
}
Run Code Online (Sandbox Code Playgroud)
但我拥有的内容是在客户端生成的HTML页面,并表示为字符串(我对它没有太大影响).如何以编程方式填充iframe的内容?
这有点复杂,请耐心等待.网站A有一个包含网站B的iframe,网站B有一个包含网站C的iframe.
网站C上有一个按钮,点击后,我想刷新网站B的网址.下面是从网站C刷新网站B的javascript,它位于iframe中
function url_update(id){
var host = 'https://websiteb.com ';
var myHost = host.split('/');
if (id != "" && myHost != ""){
try {
if (id.substring(0,1) != '/'){
id = '/' + id;
}
var dft_url = myHost[0] + '//' + myHost[2] + id;
window.parent.location.href = dft_url;
} catch(e){alert("Cannot go to the desired url location: " + dft_url);}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当行"window.parent.location.href = dft_url;"时 得到执行,我收到以下错误:
Unsafe JavaScript attempt to initiate navigation for frame with URL
'https://websiteB.com' from frame with URL
'https://websiteC.com'. The …Run Code Online (Sandbox Code Playgroud)