3

Possible Duplicate:
Download File Using jQuery
Download File Using Javascript/jQuery

$('#download').click(function() {
    var url = 'http://www.mysite.com/123.txt';
    location.href = url;
});

The button causes the browser to browse to the file instead of prompting a download. Is there a way to do this?

Community
  • 1
  • 1
Norse
  • 5,674
  • 16
  • 50
  • 86

1 Answers1

4

If you use Apache as a web server add .htaccess to the folder with the following content:

<Files *.txt>
  ForceType applicaton/octet-stream
</Files>
VisioN
  • 143,310
  • 32
  • 282
  • 281
  • +1 nice solution (if the OP uses apache) – Manse Sep 11 '12 at 08:28
  • This seems to only work if the text file is in the same folder as my web page. If i put the text file inside a subfolder such as /test, the original problem persists. I have put an .htaccess with your code in both the sub folder and parent folder and the problem is still there. – Norse Sep 11 '12 at 08:34