如何在jQuery UI对话框中显示IFRAME

| 我要升级的Web应用程序使用jQuery和jQuery UI。我已经用jQuery UI对话框替换了
window.open
<a target=_blank>
的大多数实例。例如,用于在新窗口中打开的条款和条件;现在我将jQuery UI对话框与AJAX一起使用。为了保持一致性,我计划尽可能使用它。 这样的地方之一就是页面,我将在其中拥有视频的外部链接。就像是:
<a href=\"http://website.com/videos/1.html\" target=\"_blank\"><img src=\"http://website.com/videos/1.png\"></a>
<a href=\"http://website.com/videos/2.html\" target=\"_blank\"><img src=\"http://website.com/videos/2.png\"></a>
在某些情况下,我可能会使用
target=iframe1
。现在,我不想在iframe或弹出窗口中打开内容,而是要在弹出对话框中显示内容。如何使用jQuery UI对话框实现此目的?会有陷阱吗?     
已邀请:
您可以通过多种方式执行此操作,但是我不确定哪种方法是最佳做法。第一种方法是,您可以使用给定的链接将iFrame快速添加到对话框容器中:
$(\"#dialog\").append($(\"<iframe />\").attr(\"src\", \"your link\")).dialog({dialogoptions});
另一个方法是使用ajax将外部链接的内容加载到对话框容器中。
$(\"#dialog\").load(\"yourajaxhandleraddress.htm\").dialog({dialogoptions});
两者都可以正常工作,但取决于外部内容。     
问题是: iframe内容来自另一个域 需要为每个视频调整iframe尺寸 基于omerkirk的答案的解决方案包括: 创建一个iframe元素 用
autoOpen: false, width: \"auto\", height: \"auto\"
创建对话框 在打开对话框之前指定iframe源,宽度和高度 这是代码的大致轮廓: 的HTML
<div class=\"thumb\">
    <a href=\"http://jsfiddle.net/yBNVr/show/\"   data-title=\"Std 4:3 ratio video\" data-width=\"512\" data-height=\"384\"><img src=\"http://dummyimage.com/120x90/000/f00&text=Std+4-3+ratio+video\" /></a></li>
    <a href=\"http://jsfiddle.net/yBNVr/1/show/\" data-title=\"HD 16:9 ratio video\" data-width=\"512\" data-height=\"288\"><img src=\"http://dummyimage.com/120x90/000/f00&text=HD+16-9+ratio+video\" /></a></li>
</div>
jQuery的
$(function () {
    var iframe = $(\'<iframe frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen></iframe>\');
    var dialog = $(\"<div></div>\").append(iframe).appendTo(\"body\").dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        width: \"auto\",
        height: \"auto\",
        close: function () {
            iframe.attr(\"src\", \"\");
        }
    });
    $(\".thumb a\").on(\"click\", function (e) {
        e.preventDefault();
        var src = $(this).attr(\"href\");
        var title = $(this).attr(\"data-title\");
        var width = $(this).attr(\"data-width\");
        var height = $(this).attr(\"data-height\");
        iframe.attr({
            width: +width,
            height: +height,
            src: src
        });
        dialog.dialog(\"option\", \"title\", title).dialog(\"open\");
    });
});
在此进行演示并在此处进行编码。另一个类似的例子     

要回复问题请先登录注册