开发者

Javascript: storing object in globalStorage

开发者 https://www.devze.com 2023-01-17 01:01 出处:网络
Is it possible to store objects in globalStorage or is it only ca开发者_运维百科pable of strings?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消