Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...