I want to create a very simple Javascript game using HTML5 (Canvas). But is it possible to save a simple .txt file and load a simple .txt file. I just need to store like the some simple integers. But I just want to know if javascript is allowed to save and load an external file?
Canvas
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);
}
On Chrome, you can rely on the FileSystem API (for an intro take a look here). Probably other browsers will soon add support to it.
But, if your need is just "to store like the some simple integers" I would consider local storage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With