Using firefox, I can store extension preferences using Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
What interface can I use to store preferences in Chrome? And do they get overwritten on an extension update?
Thanks
You can use the localStorage API. See http://code.google.com/chrome/extensions/options.html for an example of building an options page with this, but most simply you can do:
localStorage['foo'] = 'bar'; // Store data
var foo = localStorage['foo']; // Get data
This data won't be wiped out on extension update, either.
The new HTML5 feature to persist data locally (localStorage) should help you here.
In addition to coockies, now there are session and local storage objects, as well as, a simple version of relational database (all storing data on your local harddisk).
One hint when storing/retrieving objects to localStorage ... it is a simple implementation of the Map interface, so the safest way to persist your object is by serializing them via JSON.stringify function and parse retrieved string with JSON.parse.
Related
I'm working on a simple ruby script with cli that will allow me to browse certain statistics inside the terminal.
I'm using API from the following website: https://worldcup.sfg.io/matches
require 'httparty'
url = "https://worldcup.sfg.io/matches"
response = HTTParty.get(url)
I have to goals in mind. First is to somehow save the JSON response (I'm not using a database) so I can avoid unnecessary requests. Second is to check if the new data is available, and if it is, to override the previously saved response.
What's the best way to go about this?
... with cli ...
So caching in memory is likely not available to you. In this case you can save the response to a file on disk.
Second is to check if the new data is available, and if it is, to override the previously saved response.
The thing is, how can you check if new data is available without doing a request for the data? Not possible (given the information you provided). So you can simply keep fetching data every 5 minutes or so and updating your local file.
i have to make Contacts management website using html5 local-storage please tell me is that possible in local-storage ? and how and which api to use? if need? please guide me some initial coding step towards it.
Its possible to store the data in local storage .But, you need to think in terms of data size because different web browsers have different storage restrictions.
local storage stores items in key-value pairs and values are in string formats and you need to convert the object to string by JSON.stringify and convert back to object by JSON.parse(string).
localStorage.test="hello"; // here test is key and value is "hello".
var CustomObject={};
localStorage.object=JSON.stringify(CustomObject); store custom object
console.log(JSON.parse(localStorage.object)); //retrieve object and display
in the console.
Most browsers store around 5 mb of data .so ,check the browser support and restrctions.
You can also use sqllite storage to build the html5 application but there is limited support on this by most of the browsers.
see this website for more info http://www.html5rocks.com/en/features/storage
I am building a little HTML program (well, not little), but I have got options that I would like to permanently write to the client's machine without using cookies. reason being is cookies will expire, and have a storage limit of 4 KB. how would I do that without jquery.
Client side cookies can be deleted any time. Server side cookies cannot be deleted and the expiration date can be set. You can't write to a machine from an HTML page though, it's not allowable by any means. It would have to be a hack and a virus if such a violation would occur.
You should use HTML5 Local Storage.
To set a item to the storage
localStorage.setItem("person", "jones");
To get the item
var val = localStorage.getItem("person");
To remove the item
localStorage.removeItem("person");
Depending of what browser you use, most have 10mb of storage. read here
The storage can be stored as long as the user or the application allows it. read here
The localStorage can only store values as strings. If you want to store objects like json
var data= { person: "jones" };
localStorage.setItem("jsonPerson", JSON.stringify(data));
To read the json
var data = JSON.parse(localStorage.getItem("jsonPerson"));
How can I use HTML5 local storage to save a little exe file and then download it by clicking the button?
Localstorage as you think is not a DataBase or even the File System, it's just some plain JSON files that store tiny bits of data in key: value pairs.
If you have worked with JSON before this will be very easy to grasp the Idea behind it.
Below is an example of setting and retrieving values from Local-storage:
locastorage.setItem('KEY',JSON.stringify('VALUE'));
// KEY is kind of like the variable name and the VALUE is the actual Data
JSON.parse(locastorage.getItem('KEY'));
// You use the KEY to access the value
// Using JSON methods stringify and parse just to be on the safer side.
HTML5 Localstorage is not for files.
Have a look at Mozilla's documentation here: https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
Instead it's for key/value pairs.
// Save data to the current local store
localStorage.setItem("username", "John");
// Access some stored data
alert( "username = " + localStorage.getItem("username"));
To start a download, you may want to look at a question like Download File Using Javascript/jQuery
Does Windows.Foundation.Uri supports data URI Scheme, if yes, can I use that in Windows.UI.StartScreen.SecondaryTile as logoReference parameter? Please help.
Just tested this using the JavaScript Grid app template, and it does not work.
The constructor for Windows.Foundation.Uri will happily accept a data URI, but the constructor for Windows.UI.StartScreen.SecondaryTile throws an exception when attempting to initialize the tile with the data URI.
So you will probably need to find another way of solving this. Perhaps you can dynamically create the tile image and save it to your appdata folder, which can then be accessed via the ms-appdata:// URI scheme?
For more info on Windows Store app development, register for Generation App.