Вопрос

I am building an offline web application, and I want to be able to change the html of the page before the user saves it. since I cannot seem to find a way to trigger the save as function from javascript (except from IE), I need to just do some prep work before letting the browser save the page. I am not trying to force the user to do anything, just trying to update the page so that it saves it's state to the actual html of the page being saved. I can do this with a button, but i have to then ask the user to press Ctrl+S which is not smooth at all.

So I either need to be able to trigger a browser save from JavaScript, or handle the save event myself before allowing the default callback to happen.

Can this be done in a cross-browser supported way? I have found several pages dealing with the issue, but none clear it up as I wished, so sorry if this sounds like a duplicate.

Это было полезно?

Решение 2

This has now become possible with blobs. FileSaver.js is a cross platform solution. This will allow saving of any binary resource.

Другие советы

You could do it using Data URI's. This question is similar, a javascript-generated CSV file that would be prompted for the user to download.

There may be other solutions but I think they would be proprietary so not future-proof.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top