Javascript: storing object in globalStorage
Is it possible to store objects in globalStorage or is it only ca开发者_运维百科pable of strings?
One option would be to "jsonify" an object and then store it but I wondered if theres a better way?
var host = location.hostname;
globalStorage[host].test = {
name1: 'Ben',
name2: 'John'
};
globalStorage[host].test2 = 'hello';
alert(globalStorage[host].test.name1); //undefined
alert(globalStorage[host].test2); //hello
No, unfortunately data is only stored in globalStorage as strings.
you could take a look at the database object, if your target browser platform supports it.
精彩评论