首页 > 解决方案 > Jquery Modal Popup 未显示嵌入的 pdf 文件

问题描述

我有这个问题,我试图用模态弹出窗口来解决。当我从后面的代码中调用弹出窗口时。该链接不显示嵌入的 pdf 文件,只是空白的嵌入黑屏。

但是,当我在模式弹出窗口之外使用嵌入标签并根据后面代码的响应显示它时,pdf 文件会显示在屏幕上。所以我知道这条路是对的。我尝试在 pdffile.src 之后的代码中调用模态弹出窗口,但响应没有变化。

<script>
    function ShowPopup() {
    $(function () {
        $("#displaypdf").dialog({
            modal: true,
            height : 800,
            width : 800,
        });
     });
     return false;
    };
</script>

<div id="displaypdf" style="display:none">
     <embed id="pdffile" class="pdfsource" runat="server" />
</div>

protected void SelectButton_Click(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup();", true);
    string DirPath = Request.QueryString["Dir"];
    Button btnButton = sender as Button;
    GridViewRow gvRow = (GridViewRow)btnButton.NamingContainer;
    Label SelectLink = (Label)gvRow.FindControl("SelectLink");
    pdffile.Src = "file:Z:/testdirectory/" + DirPath + "/" + SelectLink.Text;
}

标签: c#jquery

解决方案


根据您的代码,我看到您希望浏览器加载本地资源(文件:Z:...),由于存在安全风险,大多数浏览器都不允许这样做。

要确认这是否是问题所在,请尝试更改:

pdffile.Src = "file:Z:/testdirectory/" + DirPath + "/" + SelectLink.Text;

pdffile.Src = "http://www.africau.edu/images/default/sample.pdf";

并查看文档是否加载(如果没有,请检查您的浏览器控制台是否有任何错误)。

我建议您从 http 端点提供这些文档,例如在 IIS 中设置一个虚拟文件夹,将其指向文件所在的本地网络路径(例如 Z:/testdirectory/),然后设置pdffile.Src为此虚拟目录文件路径反而。


推荐阅读