-1

I want to create a html5 page which embed a YouTube video, and I will use firefox to open it.

While playing the video I want to record some information. so basically I want to put some javascript codes on this page and the javascript codes will create a log file, write to the log file from time to time.

My question is: is it possible to use html5 local storage for creating and writing files on client side? are there any code example to create and write files on the client side using javascript and html5?

zzzzBov
  • 174,988
  • 54
  • 320
  • 367
lis
  • 135
  • 1
  • 1
  • 7
  • 6
    No. Localstorage is not the local filesystem. – Diodeus - James MacFarlane Oct 10 '12 at 14:57
  • It depends what you want to do with that data. If you just need to save few logs then yes, it can be done (but you have to read them back from within the page and to post it to the server via JavaScript). If you want to read that logs from the client machine using Windows Explorer then answer is no, it can't be done. – Adriano Repetti Oct 10 '12 at 14:58
  • I'm using firefox, not IE. and I just want to log some playing information, which are values of javascript variables. No server involved. – lis Oct 10 '12 at 15:07

2 Answers2

2

DOM storage has nothing to do with reading or writing files, but you can use it to accomplish what you're trying to do.

You can write some log information:

window.localStorage.setItem('myLog', 'someInformation');

and then you can read it later:

var storedInfo = window.localStorage.getItem('myLog'); // 'someInformation'

This will work as long as all pages interacting with the storage share the same host domain.

jbabey
  • 45,965
  • 12
  • 71
  • 94
  • Actually, localstorage will last longer than the browsing session...that's what sessionstorage is for;) – Christoph Oct 10 '12 at 15:00
  • I need to write them into log files, because I need to use these log files for analysis, like ploting figures – lis Oct 10 '12 at 15:42
  • @lis then i suggest you look at [this question](http://stackoverflow.com/questions/585234/how-to-read-and-write-into-file-using-javascript) – jbabey Oct 10 '12 at 17:04
  • that is for server side, I just want to create my own html5 page with embeded youtube video, and open the page locally. MY initial idea is to use database storage and use sqlite to get information from the database and write into a log file, is this viable? – lis Oct 10 '12 at 23:47
  • @lis as everyone in the question i linked said... you can't read or write files from the client. – jbabey Oct 11 '12 at 12:52
0

You can use local storage to store logs as a JSON object, but it's just a key-value store (an alternative to using a cookie) that is used to maintain a browser state or other client related information.. logs could be one of them.

Also, be aware that there are size limits.

There are plenty of wrappers for storing items in localstorage, jStorage, is my preference.

StuR
  • 12,042
  • 9
  • 45
  • 66
  • localstorage can only store strings so technically you can't store jsonobjects, you need to stringify them first. – Christoph Oct 10 '12 at 15:09