简体   繁体   English

如何将HTML注入iframe,并在jquery-ui对话框中显示

[英]How to inject html into iframe, and display inside jquery-ui dialog

Here I create a jqueryui dialog from an iframe and populate the iframe with some html. 在这里,我从iframe创建了一个jqueryui对话框,并用一些html填充了iframe。

In firefox this displays nothing until I add the alert. 在firefox中,直到我添加警报之前,它什么都不显示。 Is there a better way to convince firefox to draw the iframe? 是否有更好的方法说服Firefox绘制iframe?

http://jsfiddle.net/jtmx00f4/6/ 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>');

While @dandavis fiddle does work in firefox, I also found a more complete solution in this article which does not require setTimeout. 虽然@dandavis小提琴确实可以在firefox中工作,但我在本文中还找到了一个更完整的解决方案,不需要setTimeout。

http://jsfiddle.net/jtmx00f4/9/ 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>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM