简体   繁体   English

如何在没有“离开页面”对话框或任何其他提示的情况下下载文件?

[英]How to download a file without the “Leave the Page” dialog or any other prompt?

In Internet Explorer 10; 在Internet Explorer 10中; When i try to download a file; 当我尝试下载文件时; i get following dialog box: 我得到以下对话框: 在此输入图像描述

Is there someway in Jquery or HTML with which this box does not get appear when user tries to download a file in application? 在用户试图在应用程序中下载文件时,Jquery或HTML中是否存在此框不会出现?

Update : Also could not user target blank as flashing of new tab should not be there(customer requirements). 更新 :也不能用户目标空白,因为新标签的闪烁不应该存在(客户要求)。 As asked for code, it is simple link: 正如要求的代码,它是简单的链接:

<a href="www.something.com/something/something.pdf" >

jquery.fileDownload.js will help you in this. jquery.fileDownload.js将在此帮助您。

apply file path to 应用文件路径

function downloadPDF(thisobj) {        
    $.fileDownload($(thisobj).attr("href"));
}

Call this funciton on 打电话给这个功能

<a href="www.something.com/something/something.pdf" onclick="downloadPDF(this)"> 

I'd suggest you look into HTML5's download attribute . 我建议你研究一下HTML5的下载属性

Excerpt from the site: 摘自该网站:

Place the download attribute on a link... 将下载属性放在链接上...

 <!-- will download as "expenses.pdf" --> <a href="/files/adlafjlxjewfasd89asd8f.pdf" download="expenses.pdf">Download Your Expense Report</a> 

...and when the user clicks the link, the download attribute appears in the save dialog instead of the garbled mess that was there before. ...当用户点击链接时,下载属性出现在保存对话框中,而不是之前出现的乱码。 In this case, the file will be downloaded as expenses.pdf. 在这种情况下,该文件将作为expenses.pdf下载。 The download attribute also triggers a force download, something that I used to do on the server side with PHP. download属性还会触发强制下载,这是我以前在PHP服务器端执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM