c# - 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;
}
解决方案
根据您的代码,我看到您希望浏览器加载本地资源(文件: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
为此虚拟目录文件路径反而。
推荐阅读
- apache-spark - 通过 spark 优化缓存
- python - 如何在 Bigquery Python API 中使用 projection_fields 参数
- python - Logits 和标签具有不同的第一维
- c++ - long double 除法不能得到期望值
- reactjs - 使用钩子和标题功能反应导航 - 状态未更新
- git - 变基后将代码推送到 GIT 时出错
- r - 如何在 R 中找到列表中的最大值及其行和列索引?
- javascript - 移动菜单在奇数时间锁定
- knockout.js - Uncaught ReferenceError: Unable to process binding "if: function(){return (addressOptions.length > 1) }" 消息:addressOptions 未定义
- python - 如何以特定 FPS 从视频中提取帧?