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

查看:14
本文介绍了仅使用页面数据通过 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.

我想要一个按钮,当点击该按钮时,将触发另存为"对话框,该对话框将下载页面文本区域中已经存在的 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 已在页面上时),同时为用户提供快捷方式,无需创建新文件并粘贴到复制的 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天全站免登陆