gpt4 book ai didi

javascript - 如何根据JS输出显示iframe

转载 作者:行者123 更新时间:2023-11-30 10:24:00 25 4
gpt4 key购买 nike

如果用户接受警告框消息以查看网站,我想在我的网站中显示 iframe

例如,如果用户点击职业页面,我将通过提供两个选项(如果他选择"is")向他显示一个警告框。我必须在同一页面中将我的网页显示为 iframe

我通过在 JS 中编写函数尝试了以下内容

<script>
function myFunction() {
var r=confirm("Press a button!");
if (r==true) {
<iframe src="http://w3schools.com/tags/tag_div.asp" width="100%" height="100%">
</iframe>
}
}
</script>

最佳答案

单击"is"时,您可以尝试将 iframe 附加到 DOM。

    function create(htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
}

var fragment = create('<div>Hello!</div><p>...</p>');
// You can use native DOM methods to insert the fragment:
document.body.insertBefore(fragment, document.body.childNodes[0]);

关于javascript - 如何根据JS输出显示iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20393133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com