仅使用页内数据,通过Javascript触发浏览器的保存对话框 [英] Trigger a Browser's Save-As Dialog via Javascript using only On-page data

查看:181
本文介绍了仅使用页内数据,通过Javascript触发浏览器的保存对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我页面输出的一部分,我在文本区域中包含CSV格式的数据表格,以便用户可以轻松地将CSV导出复制/粘贴到所选的电子表格中。

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.

我想要一种按钮,当点击时,将触发一个另存为对话框,该对话框将下载页面中textarea中已经存在的CSV内容。

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.

目的是为了避免再次访问数据库以获取CSV导出,当它已经在页面上,同时为用户提供了创建新文件和粘贴的快捷方式在复制的CSV中。

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.

这是可能吗?

推荐答案

不要以为目前可以触发保存而不需要将某种请求返回给服务器,但是可以使用数据URI 。看看我对这个类似问题的回答

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.

这篇关于仅使用页内数据,通过Javascript触发浏览器的保存对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆