• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Javascript: Downloading txt file ...

b4u

Golden Member
Hi,

I'm looking for a way of forcing a browser like IE to download a txt file instead of opening it.

I have a button in a html page, and I want the users to download a specific txt file. The problem is that if I change the url to the txt file, IE just opens it ... of course the users can then save the file, but I want to force them to download the file ... can it be done?

Code on the button (simplified):
MyForm.action = "some_related_path\\one_big_file.txt";
MyForm.target = 'Download_Window';
MyForm.submit();

HTML Form definition:
...
<form name="MyForm" action="other_page.jsp" method="post">
...


That opens a new IE window (if 'Download_Window' isn't already opened), and opens the txt file in it ... it's a really big txt file with a report, so I'm interested in forcing the download ...


Thanks.
 
Don't know the exact mechanics in JSP, but in ASP you can specify that the content type of the output is unknown (x-unknown?), which generally makes the browser thing it should download the file...
 
Both the above solutions are good (although, do any java servers actually use .htaccess?)

There is a solution build right into html, however. Add a type attribute to the the <a> tag. So: <a href="foo.txt" type="application/octet-stream" /> or whatever mime type you find suitable. application/octet-stream seems appropriate though.
 
Thanks for the answers so far.

But as I understand, you are talking about the anchor element tag, which may be related with a link ... the problem here, is that I'm trying to avoid a link ... and so I would need some javascript code to do that download ... any chance to do it?


Thanks again 😉
 
Back
Top