user1745649
user1745649

Reputation: 137

Saving data in text file using chrome packaged app/extension

Since Chrome packaged/extensions are only written in HTML5, JavaScript and CSS, I was wondering is there a way to save data in text file without the use of server script language like php? All I need to do is save some variables values into text file when users click on Save Data. So Since I can only use JavaScript, HTML5, is there a way I could do this?

Upvotes: 1

Views: 3059

Answers (4)

Meggin Kearney
Meggin Kearney

Reputation: 51

Have you checked out the chrome apps codelab yet? Here's a link to the JavaScript version of the storage sync sample: https://github.com/GoogleChrome/chrome-app-codelab/tree/master/lab5_data/javascript/1_storage_sync.

Upvotes: 0

Vincent Scheib
Vincent Scheib

Reputation: 18600

chrome storage is likely what you want today, and better yet the upcoming chrome.syncFileSystem. See the syncfs-editor sample.

Upvotes: 1

Ahi Tuna
Ahi Tuna

Reputation: 1273

These should help you out... my app saves user creds in Chrome Storage:


// init storage
var storage = chrome.storage.sync;

// listens for events when storage changes (debug)
chrome.storage.onChanged.addListener(function(changes, namespace) {
  for(key in changes) {
    var storageChange = changes[key];
    if(debug)
      console.log('Storage key "%s" in namespace "%s" changed. Old value was: %s, new value is: %s', key, namespace, storageChange.oldValue, storageChange.newValue);
  }
});

function saveStorage() { // saves the current credz to storage
  storage.set({'username':username}, function() {});
  storage.set({'password':password}, function() {});
}

Upvotes: 1

Siddharth Gupta
Siddharth Gupta

Reputation: 897

You don't really require a text file, you can use the HTML5 localStorage API:

localStorage.foo = "myData";
//or
localStorage['foobar'] = "moreData";

to get the data back:

myDataValue = localStorage.foo;

Upvotes: 0

Related Questions