[英]Download and Load HTML file in iFrame
我試圖創建一個文件/文件夾查看器並下載到該位置,我將在網頁上顯示網絡共享目錄,它將顯示共享的所有內容。 如果文件是pdf或xls或doc,則將下載,如果其HTML,則將在頁面上的iFrame中顯示。
我已經完成了第一件事(下載文件),但是無法完成第二部分。 在iFrame中顯示HTML文件。
當我單擊HTML文件時,它會像其他文件一樣下載,並且我不確定如何不下載HTML而是顯示在屏幕上。
想法是將目錄顯示為放置FAQ文檔或頁面的KB。
這是我的下載代碼。
使用Javascript
$('#container_id').fileTree({
root: '<network path to load files from>',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: true
}, function(file) {
$("#iframe").attr("src", "/dl.aspx?file=" + file);
$('#iframe').load();
});
HTML
<div class="example">
<h2>File List</h2>
<div id="container_id" class="demo"></div>
<iframe id="iframe" style="display:none;"></iframe>
</div>
CS
if (Request.QueryString["file"] != null)
{
string actualFilePath = Request.QueryString["file"].ToString();
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
string filename = Path.GetFileName(actualFilePath);
String Header = "Attachment; Filename=" + filename;
HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
HttpContext.Current.Response.WriteFile(actualFilePath);
HttpContext.Current.Response.End();
}
也許您根本不使用此$("#iframe").attr("src", "/dl.aspx?file=" + file);
用於HTML文件。 這樣,您可以稱自己的dl.aspx
文件“想要”下載該文件。
相反,請檢查一下:
如果文件是<> HTML,則執行$("#iframe").attr("src", "/dl.aspx?file=" + file);
如果= HTML,則執行$("#iframe").attr("src", "file_path/my-html-file.html");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.