1

I am creating browser extension, which react on user clicks. When user click, it generates xpath, value, hostname etc. Until user doesn't click final "send to server's DB" I want store this data locally. I want structure like that:

  action1:
    xpath: myVal1
    value: myVal2
    hostname: myVal3

  action2:
    xpath: myVal4
    value: myVal5
    hostname: myVal6

  action3:
    xpath: myVal7
    value: myVal8
    hostname: myVal9

I think the best actual way to do this is localStorage, but I don't know how to make something like that:

  action1.xpath = 'myNewPath'
  action2.value = 'myOtherValue'

Any suggestions ?

Piotr Wójcik
  • 1,294
  • 2
  • 13
  • 26
  • 1
    possible duplicate of [Javascript + HTML5 localstorage](http://stackoverflow.com/questions/2800238/javascript-html5-localstorage) – Patrick Evans Sep 06 '13 at 13:17

1 Answers1

0

Lets say you want to store a customer:

localStorage.setItem("customer", customerInput.value);

You provide the name under which to store your data, in the above case "customer", and the variable to store, in this case it's a value from a textfield.

To retrieve these values on whatever page you like use:

var localStorageCustomerValue = localStorage.getItem("customer");

And if you don't need this data anymore you use:

localStorage.removeItem("customer");

to remove it from localstorage

Marco Baldelli
  • 3,436
  • 1
  • 21
  • 27
Ebbelink
  • 316
  • 2
  • 12