想要基于Onlclick替换iframe [英] wants to replace the iframe based on Onlclick
本文介绍了想要基于Onlclick替换iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想替换iframe,如果用户通过选择不同的输入再次点击getPrice按钮。我已经编写了代码并尝试了几件事,但没有任何结果。每次我都不能使用document.body.appendchild()。我的代码如下。请在这里建议。
I wants to replace the iframe, if user clicks on getPrice button again by selecting different input.I have written code and tried several things but nothing worked out. everytime I cant use document.body.appendchild(). My code is below. Please suggest here.
function getPrice()[
var ifrm = document.createElement('iframe');
ifrm.id = "frameID";
ifrm.setAttribute('src', 'http://40.85.176.227/invoke/Tier1ICLStd_New.Price/getPrice?CloudName=Azure East
ifrm.setAttribute('align', 'right');
//ifrm.setAttribute('marginheight', '50');
ifrm.style.margin= "auto";
ifrm.scrolling="no";
ifrm.style.border= "0";
ifrm.style.margin= "0";
//document.body.insertBefore(ifrm, document.body.firstChild);
//alert();
if(document.getElementById("frameID")==null)
{
document.body.appendChild(ifrm);
}
else
{
alert("Else"); // I am getting control till here but what code to replace the existing iframe.
//var item = document.getElementById("frameID").childNodes[0];
item.replaceChild(ifrm,item.childNodes[0]);
alert("test");
document.body.appendChild(ifrm);
//ifrm.parentNode.replaceChild(ifrm, ifrm);
}
}
推荐答案
如果你想更新iframe内容,你只需要使用这样的东西:
If you want to update the iframe content, you just need to use something like this :
function updateIframeSrc(newSrc) {
document.getElementById("frameID").src = newSrc;
}
编辑:使用HTML声明添加例子来回答评论。
EDIT : Add exemple with HTML declaration to answer a comment.
<div class="frameClass">
<iframe id="frameID" width="100%" height="1080" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0"
src="http://svn.min.not/metasite/trunk/docs/README.md">
</iframe>
</div>
这篇关于想要基于Onlclick替换iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文