This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Customize 'Save As' dialog box provided by browser at client side Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Customize Watch "Customize New topic
Author

Customize 'Save As' dialog box provided by browser at client side

shubham pateriya
Greenhorn

Joined: Dec 15, 2011
Posts: 5
I am developing a code in Java the problem I am facing is like this: I need to download a excel file on client side, when user hit the 'Download' button,a Pop up with 'Save', 'Open' and 'Cancel' button appears which is provided by browser, when user will click on 'Save' button, a 'Save As' dialog box opens which is again provided by browser, in this dialog box there is 'Save As Type' dropdown, I need to customize this dropdown and I want to show '.xls' and '.xlsx' extention type in this dropdown, and when user chooses any of extention type , file saves in that formate. So is it possible to customize client side browser given 'Save As' dialog Box and if yes than how?? Please asnwer as soon as possible.
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 307
    
    2

I don't think this is possible from the server side or with Javascript, at least I don't know of any way to do it. In my understanding the only way to do that would be with a Java applet that had the appropriate permissions.

How about a drop down menu to select format on the same page as the download button?

Also if save is your only option perhaps you're not setting the mime type of the file. If you were I would expect an open option which would open the file in Excel and it could be saved in any supported format from there.

I wish I had a better answer for you. I'll be watching the thread for someone to show us how to do what you asked.

Joe


It's not what your program can do, it's what your users do with the program.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

You cannot customize the browser's dialog. In fact, different browsers will do slightly different things. Just be sure that your response headers are correctly set so that the browser can do the "most right" thing with your response.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Crowther
author
Ranch Hand

Joined: Nov 06, 2012
Posts: 295
    
    5

It doesn't sound to me like you really do want to customize the save dialogue. The reason I'm saying this is because you say:
shubham pateriya wrote:in this dialog box there is 'Save As Type' dropdown, I need to customize this dropdown and I want to show '.xls' and '.xlsx' extention type in this dropdown, and when user chooses any of extention type , file saves in that formate.

Changing the file extension won't change the file format, if you want the file to be in a certain format you have to generate in that format on the server. All of the things you want to do happen on the server side, not at the client, by the time things have gotten to the save as dialogue on the client it's too late to be doing them.

If you want to force a file download, set the content-disposition header on the server side and ensure you've set an appropriate MIME type for the format of the file you've generated.


Read my books: Hello! HTML5 & CSS3 | HTML5 in Action | Read my blog
shubham pateriya
Greenhorn

Joined: Dec 15, 2011
Posts: 5
Rob Crowther wrote:It doesn't sound to me like you really do want to customize the save dialogue. The reason I'm saying this is because you say:
shubham pateriya wrote:in this dialog box there is 'Save As Type' dropdown, I need to customize this dropdown and I want to show '.xls' and '.xlsx' extention type in this dropdown, and when user chooses any of extention type , file saves in that formate.

Changing the file extension won't change the file format, if you want the file to be in a certain format you have to generate in that format on the server. All of the things you want to do happen on the server side, not at the client, by the time things have gotten to the save as dialogue on the client it's too late to be doing them.

If you want to force a file download, set the content-disposition header on the server side and ensure you've set an appropriate MIME type for the format of the file you've generated.




Hi..Thanks All of you for Answring my question..can it be done at this way....through my code I only provide byteArrayOutputStream and send it to client side...where client chooses the extention type from 'Save As' dialog box provided by browser(.xls or .xlsx) and somehow with the use of client side java script or ay other way we can download file in that formate
Rob Crowther
author
Ranch Hand

Joined: Nov 06, 2012
Posts: 295
    
    5

Rob Crowther wrote:Changing the file extension won't change the file format
 
Don't get me started about those stupid light bulbs.
 
subject: Customize 'Save As' dialog box provided by browser at client side
 
Similar Threads
packages and CLASSPATH
Getting ready for the job market quickly - so many technology combinations, how to focus ?
Fetch 10K rows from table
Disable HTML frame using Javascript
How to create xml and csv file a client side using jsp and servlet?