Set Local Storage Item

Definition:

NDLLibrary.setLocalStorageItem(itemName, value)

 

Description:

Store a value in a local HTML5 storage item.

 

Parameters:

This function has two parameters:

itemName - Required

A name of your choice for the storage item to be created. The name is case-sensitive.

 

value - Required

The string of characters you want to be stored in the item.

Note: This function does not use the default ndlParams object.

 

Returns:

true if local HTML5 storage is supported by the user's browser.

false if local HTML5 storage is not supported by user's browser.

 

Code Sample:

// Store user's name in local storage

var itemName= "myStore",

value = username + " " + userSurname;

return NDLLibrary.setLocalStorageItem(itemName, value);

 

Notes:

The return value doesn't indicate whether the item has been successfully created or not, only whether local HTML5 storage is supported.

 

Using as Predefined Action in Event:

When assigned to an Event as a predefined action, you will need to generate a JavaScript function and then edit the skeleton script created to provide a name for the storage item and the value to store in it. The automatically generated code looks like this:

return NDLLibrary.setLocalStorageItem(ndlParams);

You will see in the code sample above we have added the lines:

var itemName= "myStore",

value = username + " " + userSurname;

before the line calling the function. You will need to add similar lines with the following changes:

- Substitute myStore with the name you want to give to the storage item, leaving the double quotes around it.

- Substitute username + " " + userSurname with the value you want to store. If you are specifying a text string, e.g. John Smith, you will need to enclose the text in double quotes, e.g. "John Smith".

 

 


See also:

Get Local Storage Item

Remove Local Storage Item