0

我正在开发一个 asp.net Web 应用程序,其中我在 jquery 对话框中显示 pdf,而 pdf 在 Iframe 中。我的代码是

  if (int.Parse(Request.QueryString["option"].ToString()) == 0)
    {
        showPDF(DocumentId, perId);
        mediaRep.MediaViewLog(memberId, DocumentId);
        litScript.Text = "<script>$(function(){$( '#dialog' ).dialog( 'destroy');$(\"#showPdf\").dialog({height: \"auto\",width:\"auto\",modal: true ,buttons:{OK: function () {$(this).dialog(\"close\");window.location=\"PdfSearch.aspx\"}},close:function(){closeDialogPer(\"" + perId + "\");window.location=\"PdfSSearch.aspx\"}});});</script>";
    }

  publicvoid showPDF(Guid DocumentId, int perId)
    {
        litObj.Text = "<iframe  type=\"application/pdf\" class=\"noprint pdfPreviewSettings\" src=\"/Search/GetPdfFile.ashx?MediaId=" + DocumentId + "&FileType=Document" + "&PerId=" + perId +
                                            "\" onclick=\"disableRightClick();\"  width=\"1150\" height=\"750\" ><strong class=\"pdfError \">Please contact your system administrator for installation of adobe acrobat reader.</strong></iframe>";
    }

问题是,当 pdf 显示在对话框中时,iframe 中的 Web 处理程序调用了两次,而没有对话框处理程序调用了一次。使用 jquery 对话框调用处理程序的原因是什么以及如何修复它。

4

1 回答 1

1

调用时出现 2 个请求的原因dialog是 iframe 在页面上并且已经加载了一次,但是dialog调用从其当前父元素中删除了 iframe,然后将其附加到其他一些元素(如页面上的 div 中心),这会导致iframe 重新加载其内容,您无法避免此问题。

解决方案是不在 html 标记中设置 iframe src,然后在 iframe 上调用对话框函数后,将 iframe src 设置为 url。

$("#showPdf").dialog(...);
$("#showPdf").attr("src","<here goes the url to be loaded>");
于 2013-05-16T10:55:58.163 回答