Guest User

Untitled

a guest
Jun 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. //Local storage only stores string
  2. //so if you do this in one browser.....
  3.  
  4. var obj = {'name':'rick', age:100};
  5.  
  6. localStorage['empId1'] = obj;
  7.  
  8.  
  9. //Then this in the other browner (same URL)...
  10.  
  11. var obj = localStorage['empId1']
  12.  
  13. //obj is this string... "[object Object]"
  14.  
  15. //This is not actual very useful.
  16.  
  17. //Instead you need to do this
  18.  
  19.  
  20. //In the first browser do this.
  21. localStorage['empId1'] = SC.json.encode(obj);
  22. // which stores this string "{"name":"rick","age":100}"
  23.  
  24. //Then retrieve it as follows in the other browser:
  25. var obj = SC.json.decode(localStorage['empId1']);
  26.  
  27. // now obj.name is "rick"
Add Comment
Please, Sign In to add comment