Open Bug 1302919 Opened 8 years ago Updated 2 years ago

opening a save as download dialog with javascript code to download a file created

Categories

(Core :: DOM: Core & HTML, enhancement, P3)

45 Branch
All
Windows 7
enhancement

Tracking

()

UNCONFIRMED

People

(Reporter: nilesh.apatil, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

Steps to reproduce:

I need to display via javascript code an Save-AS file dialog-box in Firefox for an file. Let me know if there are any ways to achieve it in Firefox browser.

Found few options like using open source JS library FileSaver.js etc. But it works only in Chrome etc.

Other references are overriding User profile setting in firefox which is not preferred option for us.
Also HTML5 SaveAs dialog is not supported in Firefox?

Any information would be helpful


Actual results:

In Firefox - the SaveAs dialog does not appear via Javascript code .

Note: Doing an explicit User Settings is not an option for me


Expected results:

I should be able to programmatically show the SaveAs dialog box via Javascript code for  an file
what do you want to save?
existing file on server side, or some data created on client side?
Flags: needinfo?(nilesh.apatil)
I need to Save an File which contains data (.csv) file which is generated client side only and want to show the File SaveAs Dialog box.

How can i trigger the SaveAS dialog box via JavaScript code.

I tried following options but no luck so far. Please provide your inputs

Option 1) Mozilla Component Class(nsIFilePicker) via normal javascript ,Can i do this ? I am not writing an FireFox add on etc. Need to just show SaveAs dialog box each time for file download.

Refer - https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Tutorial/Open_and_Save_Dialogs

Option 2) Tried Open source library FileSaver.js -  This works in other browsers but not in Firefox https://github.com/eligrey/FileSaver.js

Option 3) Can i through Javascript code override User settings (about:Config)
browser.download.useDownloadDir;true
browser.download.lastDir


Thanks,
Neelesh
ah, sorry, I don't know any way that can show SaveAs dialog even if user checked "Do this automatically for files like this from now on" on SaveAs dialog before.

except that, you can do by creating link and invoke click method on it, like:

  var a = document.createElement("a");
  a.setAttribute("download", "FILENAME_HERE.txt");
  a.setAttribute("href", "data:text/csv,FILE_BODY_HERE");
  document.body.appendChild(a);
  a.click();
Flags: needinfo?(nilesh.apatil)
The above code will just trigger direct download to the specified path of the User download folder.

Can i explicitly trigger SaveAs File dialog box when your clicks on the hyperlink.
Any comments on the issue. Can you assign the defect to the team for any workaround on the issue.
Component: Untriaged → Widget: Win32
Product: Firefox → Core
Severity: normal → major
Priority: -- → P2
OS: Unspecified → Windows 7
Hardware: Unspecified → All
Whiteboard: SaveAs File Dialog Window
at least this is not Widget issue.
moving back to untriaged.

about File API, it was filed as bug 557540, and WONTFIXed.
Component: Widget: Win32 → Untriaged
Product: Core → Firefox
See Also: → 557540
Changing the Priority and Severity back to their original values. 
Nilesh, those fields are should be set only by the developers.
Severity: major → normal
Priority: P2 → --
Whiteboard: SaveAs File Dialog Window
Hi Tooru, 

I'm not sure if this is an issue or an enhancement request but from what I understood he wants to open the "Save As" window, and as afar as I know, Firefox uses the Windows one for this type of operations. That's why I thought that the best component choice would be "Widget: Win32".

Regarding FIle API. I don't think that he needs a new interface for this, he just wants to find a way to call the Windows one for this operation.

If you still consider that the component I chose is not the right one, can you help me find a better one ? If it remains untriaged this won't help either of us.

@Nilesh, I did some digging around and found some links that might be of help to you:
http://www.nullskull.com/q/10411164/to-display-save-as-dialog-box-in-firefox.aspx
http://stackoverflow.com/questions/8877463/showing-a-save-as-dialog-box-in-firefox?rq=1
Flags: needinfo?(nilesh.apatil)
Flags: needinfo?(arai.unmht)
Thanks. Checked the reference link but it still does not solve the issues

1.FireFox does not support document.execCommand which triggers SaveAs dialog. This same thing works fine in IE. eg: document.execCommand("SaveAs",null,"file.csv")

2.I am generating the File data for download on client side for the export. So i cannot set the MIME type/Content-Disposition header value.

3.Also firefox does not support w3c API - html5-saveas option

Is there any alternate way in Firefox to trigger SaveAs file dialog box?

Thanks,
Neelesh
this would be an enhancement request, to have alternative for other non-standard/not-supported APIs.
Core - DOM would be a right place.
(or perhaps just a spec issue to create a better API?)


(In reply to Ciprian Muresan [:cmuresan] from comment #8)
> I'm not sure if this is an issue or an enhancement request but from what I
> understood he wants to open the "Save As" window, and as afar as I know,
> Firefox uses the Windows one for this type of operations. That's why I
> thought that the best component choice would be "Widget: Win32".

The dialog can be shown by just trying to download a file (comment #3).
But if user chose not to show it and just save it to default directory,
the dialog is not shown and the file is downloaded to the directory without any other interaction.

nilesh wants the saveAs dialog to be always shown.  So dedicated API (or maybe tricky hack) is needed here.


> Regarding FIle API. I don't think that he needs a new interface for this, he
> just wants to find a way to call the Windows one for this operation.

The issue here is that we don't have any API for web content.

If we have the API and the save-as dialog isn't properly shown due to some underlying OS-specific issue, this would be a Widget bug, but it's not the case.
Severity: normal → enhancement
Component: Untriaged → DOM
Flags: needinfo?(arai.unmht)
Product: Firefox → Core
Flags: needinfo?(nilesh.apatil)
Priority: -- → P3
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.