javascript - Triggering a file download without any server request -


Greetings,

I'm working on a JS-based application that does some complex work and Logs & lt; Div & gt; Some information on (in fact, up to hundreds of rows).

My goal is "Save Log" button that triggers the browser's download dialog

  • < P>
  • The file has complete control over S / She should be able to store / store it for future reference; To get help in addressing some issues, by mailing it to the Support Department, Load it back into the app etc. HTML5's Web Store API does not help here (data is saved in a browser-defined location and it can not be easily retrieved except from JS).
  • The application should be able to work offline (at least in some circumstances), and the efficiency is that I think of posting the data to bring it back with the "content-nature" header to sacrifice.
  • The file is correctly text / plain , therefore the browser might suggest normal actions (such as "Open on Notepad") as if with normal file downloads. It can be seen as the specific aspect of the first requirement.
  • Send the user & lt; Div & gt; It is definitely terrible to say that a content of copy and paste in a text editor is definitely terrible, and this is the reason I am trying to escape.
  • I am searching on this site, on WHATWG and W3C sites and generally without success on the Web. Is this all possible?

    The closest I've found is using data: url. My first try, could not get the content type through a post operation, so it returned to the UA mutation. Send me a & lt; A & gt; By looking at the link as a button and giving it a type attribute, it gets a bit better, but again the UA will play very smart and instead of saving the content (and the user At that step, worse than getting the copy-paste approach by asking the browser to save the file, the page's savings vary deeply between browsers).

    Unfortunately this is not something you can do with normal browser capabilities. Like a flash or browser-specific plug-in you'll find something you need, but security limits within JavaScript will not allow you to download arbitrary data created within the browser.

    Apart from this, the 'data' url is not supported in all browser / version combinations. I'm not sure whether your users are complying with what browser they are using or not, but what can you do with that solution?


    Comments

    Popular posts from this blog

    c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

    Calling GetGUIThreadInfo from Outlook VBA -

    Obfuscating Python code? -