Local Storage
Block Group: | Browser API |
Icon: |
Allows your project to store information in the user’s browser, over multiple sessions and browser windows.
For information on using dataflow blocks, see Dataflow.
Input/Output Properties
These properties can take input and give output.
- key (string)
- global (boolean)
- value (string or multi-line text input)
key sets or returns the key for a key-value pair.
global specifies whether this block sets and returns the global or non-global value for the key.
- TRUE: This block sets and returns this user’s global value for the key, which stays consistent over any DGLux5 project.
- FALSE: This block sets and returns this user’s non-global value for the key, which applies only to this DGLux5 project.
value sets or returns the value for a key-value pair.
Remarks
- To store multiple key-value pairs, use multiple blocks.
Model
This is a basic use of the block.
Use Case
This section covers how to pass a value into a Local Storage block using JavaScript.
Changes to value from JavaScript do not take effect if the JavaScript is in the developer console for the same DGLux5 frame. Changes take effect only if the JavaScript is in an IFrame, or a different .dg5
file from the Local Storage block.
To pass a value into a Local Storage block:
- Create a Local Storage block, and define the global and key properties.
Use the following syntax to append code to define the value:
window.localStorage['dg:project:key1'] = "value1";
- Replace
project
with the name of the project. If global is set to TRUE,project
is blank, so the syntax isdg::key1
. - Replace
key1
with the name of the key. This must match the key property of the Local Storage block. - Replace
value1
with the value of the key.
More Resources
This thread in the DGLogik Community Forum addresses the local storage block: