Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

javascript - Save Coordinates in a Text file

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...