user3055828
user3055828

Reputation: 21

How do I write data to a file with Javascript?

I made a game with javascript using this tutorial as a base: http://html5gamedev.samlancashire.com/making-a-simple-html5-canvas-game-part-3-drawing-images/ How do I get it to write the data from the item counter (var itemCounter = 50;) to a text file named savedata.txt? I googled it, but no helpful results came up. Can someone help me?

Upvotes: 1

Views: 272

Answers (4)

roo2
roo2

Reputation: 6071

Writing a file is posible with the new FileWriter and FileSystem APIs.

More mature solutions (not using files) have already been mentioned

Upvotes: 1

roo2
roo2

Reputation: 6071

Javascript does not support working with files, for data storage several options are available:

Upvotes: 0

LJᛃ
LJᛃ

Reputation: 8153

Its not possible to store the data as a file on the client. But you can use localstorage, websql, indexeddb or simply cookies for it. Note that all of these storages have different properties in terms of lifetime.

You could also create a blob using the blobapi and then create a dataurl and request the user to save it, using drag and drop + fileapi to read the data, this approach however will make it easy for users to modify the data.

Upvotes: 1

C. S.
C. S.

Reputation: 823

Technically, you can create a server with nodejs [which is built with javascript]. Details can be found here

Upvotes: 1

Related Questions