0

I prefer Chrome, but I would like it to operate also in other browsers. So, how to make a simple button that will onClick call a function to save html page as html file? Pretty much the same like user presses Right click > Save As.

I have two buttons already, window.print() for printing and location.reload() for refreshing the page, and I must add that this html page is running locally, so there's no web server. Is it possible with onClick JavaScript as two examples above?

mpavlovic89
  • 749
  • 3
  • 16
  • 37
  • http://stackoverflow.com/questions/4799669/trigger-a-browsers-save-as-dialog-via-javascript-using-only-on-page-data – Zero Fiber Feb 27 '14 at 18:30

2 Answers2

2

I don't think this is possible, as this would likely be a security violation.

You mention specifically that you are running this locally. Does that mean you are trying to create some sort of application? If so, you might throw it in to something like Brackets Shell. If you put it in there, you can implement your own native function to trigger the "Save As" dialog. It'd be a bit more complicated, but probably one of the only ways to accomplish it if you really needed an on-page Save As button.

samanime
  • 25,408
  • 15
  • 90
  • 139
0

This is not currently possible using pure JS, but you can iterate through the document and export the contents to a file manually.

See this similar post: Export DOM

Community
  • 1
  • 1
Pat Burke
  • 580
  • 4
  • 13