Javascript创建IFrame
我正在尝试在父div中创建IFrame元素。这是我的javascript代码:Javascript创建IFrame,javascript,Javascript,我正在尝试在父div中创建IFrame元素。这是我的javascript代码: var e = document.createElement('iframe'); e.setAttribute('src', 'http://www.example.com/); e.setAttribute('scrolling', 'no'); e.style.border = "none"; e.style.overflow = "hidden"; e.style.overflowX = "hidden";
var e = document.createElement('iframe');
e.setAttribute('src', 'http://www.example.com/);
e.setAttribute('scrolling', 'no');
e.style.border = "none";
e.style.overflow = "hidden";
e.style.overflowX = "hidden";
e.style.overflowY = "hidden";
var c = document.getElementById('parentDiv');
c.appendChild(e);
当我在另一个站点中使用此脚本(Emmbed代码)时,我得到以下结果:
<div>
<div id="parentDiv">
<iframe src="http://www.example.com/" scrolling="no" style="width: 250px; height: 60px; border: medium none; overflow: hidden;">
</iframe>
<iframe src="http://www.example.com/" scrolling="no" style="width: 250px; height: 60px; border: medium none; overflow: hidden;">
</div>
<script type="text/javascript" src="http://example.com/path" >
</div>
如您所见,前面的代码正在创建两个iframe(而不是一个),我不知道为什么
为什么会发生这种情况?注意,(可能不是当前的问题):
e.setAttribute('src','http://www.example.com/);代码>缺少它的结束报价。javascript是如何调用的?它在函数中吗?您可能会调用该函数两次吗?我们可能需要看到更多相关的代码。我无法重现这个问题,这里显然还有其他问题: