我需要在新瀏覽器選項卡中打開pdf文件。這個怎麼做。 我正在使用如何在javascript中打開pdf文件新瀏覽器窗口
var docLocation = '../downloads/doc.pdf';
window.open(docLocation,"resizeable,scrollbar");
但它打開瀏覽器的下載對話框。如何實現這一目標?
我需要在新瀏覽器選項卡中打開pdf文件。這個怎麼做。 我正在使用如何在javascript中打開pdf文件新瀏覽器窗口
var docLocation = '../downloads/doc.pdf';
window.open(docLocation,"resizeable,scrollbar");
但它打開瀏覽器的下載對話框。如何實現這一目標?
顯示PDF的能力完全取決於用戶是否有可用於顯示PDF的插件,並且它們的設置被設置爲以這種方式處理PDF文件。
這裏有一些flash小部件,可以用來向用戶展示pdf內容,但直接回答你的問題,你不能控制用戶如何選擇處理pdf文件的偏好。
這裏
<a href="javascript:void(0);" onclick="javascipt:window.open('YourPDF.pdf');" class="popup">Clic to open.</a>
你需要在你的電腦已經安裝了讀卡器
確保Content-Type頭是 '應用程序/ PDF' 而不是 '應用程序/八位字節流'
我嘗試了上述所有解決方案,但都沒有爲我工作,我在mvc 3上運行javascript,並且在Chrome和Firefox上安裝了剃鬚刀,adobe 11作爲附加組件。這是我爲了讓它在所有上面的瀏覽器上工作而做的。
製造PDF控制器,在主視圖剃刀代碼從JavaScript這樣
稱爲:
var URL_OPEN_REPORT_PDF = "@Url.Content("~/Report/OpenPDF/")";
的javascript:
var sURL = URL_OPEN_REPORT_PDF;
sURL = AddURLParameter(sURL, "ReportArchive", moControl.treeOrganization.getUserData(sItemUI, "reportarchive"));
window.open(sURL);
控制器ReportController.cs:
[Authorize]
[HttpGet]
public ActionResult OpenPDF(string ReportArchive)
{
PDFResult oPdfResult = new PDFResult();
ReportArchive oReportArchive;
var serializer = new JavaScriptSerializer();
oReportArchive = serializer.Deserialize<ReportArchive>(ReportArchive);
string FilePath = Server.MapPath(string.Format("~/Content/Reports/{0}", oReportArchive.FileName));
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if (FileBuffer != null)
{
oPdfResult.Length = FileBuffer.LongLength;
oPdfResult.FileBuffer = FileBuffer;
Response.BinaryWrite(FileBuffer);
} return View("PDF", oPdfResult);
}
視圖模型PDFResult.cs:
public class PDFResult
{
/// <summary>
/// Content Length
/// </summary>
public long Length { get; set; }
/// <summary>
/// Content bytes
/// </summary>
public Byte[] FileBuffer { get; set; }
}
查看PDF.cshtml:
@model Report.PDFResult
@{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", Model.Length.ToString());
Layout = null;
}
此代碼將在一個完整的窗口中打開一個PDF文檔從JavaScript
var pdf = MyPdf.pdf;
window.open(pdf);
打開窗戶的函數看起來像這樣:
function openPDF(pdf){
window.open(pdf);
return false;
}