Cookie

Enables apps to store, retrieve, and delete client side data. The data is stored in the Atlassian product's localStorage, not the app's localStorage. This data cannot be seen by other apps.

This module is named "Cookie" as it originally used cookies to store data. It now uses localStorage, but the name has been kept for backwards compatibility.

Methods

save (name, value, expires)

Save a value to localStorage.

Parameters

NameTypeDescription
name

String

The name to store the data against.

value

String

The value to store.

expires

Number

Optional, the number of days before expiry, defaults to 365.

Example

1
AP.cookie.save('my_cookie', 'my value', 1);

read (name, callback)

Get a value from localStorage (falls back to cookie for legacy support).

Parameters

NameTypeDescription
name

String

The name to store the data against.

callback

function

The callback to pass the data to.

Example

1
2
AP.cookie.save('my_cookie', 'my value', 1);
AP.cookie.read('my_cookie', function(value) { alert(value); });

erase (name)

Deletes a value from localStorage.

Parameters

NameTypeDescription
name

String

The name of the data to remove.

Example

1
2
3
AP.cookie.save('my_cookie', 'my value', 1);
AP.cookie.read('my_cookie', function(value) { alert(value); });
AP.cookie.erase('my_cookie');

Rate this page: