最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Trigger a Browser's Save-As Dialog via Javascript using only On-page data - Stack Overflow

programmeradmin1浏览0评论

As part of my page's output, I'm including a CSV formatted version of a data table in a text area, so that the user can easily copy/paste a CSV export into their spreadsheet of choice.

I would like a way to have a button that, when clicked, will trigger a Save-as dialog that will download the CSV contents already present in the textarea on the page.

The intention is to avoid another trip to the database to get the CSV export, when it is already on the page, while providing the user a shortcut around having to create a new file and paste in the copied CSV.

Is this possible?

As part of my page's output, I'm including a CSV formatted version of a data table in a text area, so that the user can easily copy/paste a CSV export into their spreadsheet of choice.

I would like a way to have a button that, when clicked, will trigger a Save-as dialog that will download the CSV contents already present in the textarea on the page.

The intention is to avoid another trip to the database to get the CSV export, when it is already on the page, while providing the user a shortcut around having to create a new file and paste in the copied CSV.

Is this possible?

Share Improve this question asked Jan 25, 2011 at 22:37 IanIan 12.3k27 gold badges63 silver badges78 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

I don't think it's currently possible to trigger save as without doing some sort of request back to the server, but it's possible to export data from a loaded page using a Data URI. Have a look at my answer to this similar question.

发布评论

评论列表(0)

  1. 暂无评论