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

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

问题描述

由于我的页面的输出,我包括在文本区域一个数据表的CSV格式版本,使用户可以轻松地复制/ CSV格式输出粘贴到他们选择的小号preadsheet。的一部分

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内容已经present在页面上的文本区域。

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 。看一看<一个href=\"http://stackoverflow.com/questions/3286423/is-it-possible-to-use-any-html5-fanciness-to-export-local-storage-to-excel/3293101#3293101\">my回答这个类似的问题。

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天全站免登陆