Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file without the "Leave the Page" dialog or any other prompt?

In Internet Explorer 10; When i try to download a file; i get following dialog box: enter image description here

Is there someway in Jquery or HTML with which this box does not get appear when user tries to download a file in application?

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" >
like image 848
fatherazrael Avatar asked Oct 22 '25 05:10

fatherazrael


2 Answers

jquery.fileDownload.js will help you in this.

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)"> 
like image 131
Parth Trivedi Avatar answered Oct 23 '25 19:10

Parth Trivedi


I'd suggest you look into HTML5's download attribute.

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. The download attribute also triggers a force download, something that I used to do on the server side with PHP.

like image 39
Alexis Tyler Avatar answered Oct 23 '25 18:10

Alexis Tyler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!