如何使用jQuery在新窗口中打开带有.pdf文件扩展名的所有链接?我需要改变这一点:
<a href="domain.com/pdf/parkingmap.pdf">parking map</a>在这方面:
<a href="domain.com/pdf/parkingmap.pdf" target="_blank">parking map</a>如果有帮助,所有文件都在/pdf文件夹中。
发布于 2019-05-22 22:51:57
<a onclick=ViewPdf(test.pdf) href="">
function ViewPdf(FileName) {
var url = '../Home/GetPDF?fileName=' + FileName;
window.open(url, '_blank');
}
现在像下面这样编写ActionResult
public ActionResult GetPDF(string fileName)
{
try
{
byte[] fileData = System.IO.File.ReadAllBytes(Functions.GetConfigValue("CDXFilePath") + fileName);
string resultFileName = String.Format("{0}.pdf", fileName);
Response.AppendHeader("Content-Disposition", "inline; filename=" + resultFileName);
return File(fileData, "application/pdf");
}
catch
{
return File(Server.MapPath("/Content/") + "FileNotFound.html", "text/html");
}
}https://stackoverflow.com/questions/14140446
复制相似问题