【问题标题】:iframed jquery ui dialog not working properlyiframed jquery ui 对话框无法正常工作
【发布时间】:2014-10-18 19:20:11
【问题描述】:

我在我的 jquery ui 对话框中显示 iframe。在对话框内,我正在显示添加/编辑等操作的表单。我正在使用以下 HTML 代码:

@* This is container which is open as popup *@
<div id="dialog">
   <iframe frameborder="0" id="ContentIframe" src=""></iframe>
</div>

CSS 是:

#ContentIframe {
border: medium none;
height: 100%;
width: 100%;
float:left;
}

而jquery代码是这样的:

/* This method opens iframed dialog box */
function ShowPopup(Url, DialogTitle, W, H) {

    /* Setting for dialog box */
    $("#dialog").dialog({
        title: DialogTitle,
        autoOpen: false,
        modal: true,
        resizable: false,
        width: W,
        height: H,
        open: function (ev, ui) {
           /* Setting URL to open in iframe */
           $('#ContentIframe').attr('src', Url);
        }
    });

    /* Opening dialog box */
    $('#dialog').dialog('open');
}

当调用 ShowPopup 方法时,我通过 URL 在弹出窗口中打开。这很好用,但问题是,当我打开说 URL-A 然后关闭弹出窗口然后尝试在与 URL-B 相同的页面上打开弹出窗口时,首先显示以前的 URL-A 的内容,然后在几秒钟后显示 URL-B 的新内容.我认为它是在 iframe 中打开的,所以下一个 URL 需要一些时间来加载,但是为什么旧的(以前的)URL 的内容仍然存在,因为我已经关闭了弹出窗口。

在此先感谢...

【问题讨论】:

    标签: jquery jquery-ui iframe popup


    【解决方案1】:

    我们需要查看您的关闭功能,我的猜测是您只是隐藏了弹出 div,所以正如您所说,新的 url 需要一些时间来加载,所以在此之前您会看到上一页。

    最简单的解决方案是在关闭弹出窗口时将 iframe src 设置为空页面:

    $('#ContentIframe').attr('src', 'about:blank');
    

    或在您打开文档时将其链接,这会将其设置为空白,然后立即您的新 URL(但它是否对您来说足够快,未经测试):

    open: function (ev, ui) {
       $('#ContentIframe').attr('src', 'about:blank')
                          .attr('src', Url);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-09
      • 2016-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多