简体   繁体   中英

IE8 and Safari open .csv file in browser. How do I make it so it opens a download option?

I am trying to make a jsp page that lets user to download a .csv file. It wors fine on FF, chrome and IE10, ie, it opens a popup to give the user the option to download/save the file. But in IE8 and safari the csv file open in the browser. How do I make it work. The code that I have is

onclick="window.location.href='../sample/SampleImport.csv'; return false;" />

Thank you in advance

One option would be to link off to an actual download page. That page would then push the file down as a response with a content-type of application/octet-stream

To do this, you'll probably need to write a servlet: http://balusc.blogspot.com/2007/07/fileservlet.html

As a side note, my first instinct was to response.write() out the document, but apparently that's not the correct approach .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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