在文本文件中保存坐标 [英] Save Coordinates in a Text file

查看:159
本文介绍了在文本文件中保存坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HTML和javascript绘制一条线并显示该线的坐标。



这里是演示上的jsfiddle。



我想将这些坐标存储在文本文件中,旁边的绘图框。

这是我的HTML文件

< canvas id =canvaswidth =300height =300style =border:1px solid black;> < / canvas>
< div id =coord>< / div>
< div id =coords>< / div>


解决方案

W3C File API一度包括 saveAs 方法允许您使用javascript将文件保存到用户本地文件系统。



saveAs 部分文件API现在已被浏览器删除非常好的安全原因。



Eli Gray编写了一个漂亮的插件,允许您将文件(如点文件)下载到用户本地文件系统。用户必须确认他们希望下载的文件保存到其文件系统之前。同样,这是非常好的安全原因。



FileSaver插件: https://github.com/eligrey/FileSaver.js/



您也可以查看Juhana的建议使用 web storage (也称为 localstorage )将点数据存储到沙箱存储区域。存储区域位于用户本地文件系统上,但访问仅限于您的网页 - 沙箱。 Localstorage不要求用户确认保存。


I am using HTML and javascript to draw a line and display the coordinates of that line.

Here is the Demo on jsfiddle.

I want to store these coordinates in a text file instead of displaying them next to the drawing box. Can you help me figure it out.

This is my HTML file

<canvas id="canvas" width="300" height="300" style="border: 1px solid black;">    </canvas>
<div id="coord"></div>
<div id="coords"></div>

解决方案

At one point the W3C File API included a saveAs method which allows you to save files to a users local file system using javascript.

The saveAs part of the File API has now been removed by browsers for very good security reasons.

Eli Grey has coded a nice plugin that allows you to download files (like your points file) to a users local filesystem. The user must confirm that they want the downloaded file before it's saved to their filesystem. Again, this is for very good security reasons.

The FileSaver plugin: https://github.com/eligrey/FileSaver.js/

You might also check out Juhana's suggestion of using web storage (also known as localstorage) to store your points data to a "sandboxed" storage area. The storage area is located on the users local filesystem, but access is restricted to your web page only--"sandboxed". Localstorage does not require a user to confirm the save.

这篇关于在文本文件中保存坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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