0

I've developed a web app (nodewebkit) and I have a link "linked" to a pdf document:

<div id="container">
  <a href="path/document.pdf"></a>
</div>

I've noticed that in some computers, when user click on link, browser propose to download the file. In others, instead, browser show pdf inside the page.

How can I get the same behavior on all browsers? I need the download option!

I suppose that I've to prevent default behaviour:

$('container').on('click', 'a', function(e) {
   e.preventDefault();
   ...
});
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146
  • The pdf is always downloaded. Sometimes, after downloading, it opens in the browser. – DwB Jun 16 '14 at 12:56
  • First, I don't want use php. Ok, so how can I prevent opening from browsers? – Luca Davanzo Jun 16 '14 at 12:59
  • The answer is you can't. Take chrome as an example, chrome will only download the pdf file instead of viewing it if you disable the "Chrome PDF Viewer" plugin in `chrome://plugins/`. – merlin Jun 16 '14 at 13:05
  • so the solution is to disable plugin from nodewebkit manifest ----- "webkit": { "plugin": false } – Luca Davanzo Jun 16 '14 at 13:10
  • 1
    I don't believe that this is truly a duplicate of the referred question. That question was specifically asking about implementing `Content-disposition: attachment` where this question is more general and has several other possible (or even more appropriate) solutions. While it is useful indormation, it would be more appropriate to include the link as part of a suggested answer. – OldGeeksGuide Jun 16 '14 at 22:44

1 Answers1

3

You could use the HTML5 download attribute like so:

  <a href="path/document.pdf" download> Click to download</a>

This opens a "save as" dialog regardless of file type without taking you away from the page.

Suvimo
  • 240
  • 1
  • 6
  • 18