gpt4 book ai didi

javascript - 如何将html注入(inject)到iframe中,并在jquery-ui对话框中显示

转载 作者:行者123 更新时间:2023-11-28 07:17:05 25 4
gpt4 key购买 nike

这里,我从 iframe 创建一个 jqueryui 对话框,并使用一些 html 填充该 iframe。

在 Firefox 中,在我添加警报之前,它不会显示任何内容。有没有更好的方法让 Firefox 绘制 iframe?

http://jsfiddle.net/jtmx00f4/6/

function fancyDialog(htm) {
$('<iframe></iframe>').dialog({
open: function () {
//alert('presto!');
var doc = this.contentDocument || this.contentWindow.document;
doc.body.innerHTML = htm;
}
});
}

fancyDialog('<html><body><p>Hello</p></body></html>');

最佳答案

虽然 @dandavis fiddle 在 Firefox 中可以工作,但我还在 this article 中找到了更完整的解决方案不需要 setTimeout。

http://jsfiddle.net/jtmx00f4/9/

function fancyDialog(htm) {
$('<iframe></iframe>').dialog({
open: function () {
this.contentWindow.contents = htm;
this.src = 'javascript:window["contents"]';
}
});
}

fancyDialog('<html><body><p>Hello</p></body></html>');

关于javascript - 如何将html注入(inject)到iframe中,并在jquery-ui对话框中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30741021/

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