2

I'm building a GUI for a plugin and it runs in Firefox locally. Is there any way to save .data for objects out to a .js or .txt file then have the ability to load these saved files (which would just contain the number of elements a user has added and their associated.data)? I've read about it elsewhere and can't seem to get a solid answer. If this isn't possible would there be a workaround for this? Thanks!

Aaron
  • 2,482
  • 1
  • 26
  • 56
  • 3
    Have you looked at these html5 features: file api, local storage, or IndexedDB? – James May 25 '12 at 16:24
  • This may be of interest: http://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file – Imp May 25 '12 at 16:25

1 Answers1

0

Since html5 you can use the LocalStorage API. Nowadays almost all browsers support it:

// Check if it is supported in your browser
function supports_html5_storage()
{
      try
      {
        return 'localStorage' in window && window['localStorage'] !== null;
      }
      catch (e)
      {
        return false;
      }
}

//make use of it:
if( supports_html5_storage() == true )
{
   localStorage.setItem("myItem", "myData");
   var myDataString = localStorage.getItem("myItem");
   alert(myDataString);
}
Alex
  • 1,602
  • 20
  • 33