This topic explains how to use CpExtra persistence variables to store data for use later in the same project, or by different projects running on the same device.
Browser Storage Variables
All browsers that are supported by Captivate have a feature called Web Storage. Web Storage allows web pages to save variables inside the browser which can then be read by that page later, or by any other page in the same domain.
Web Storage is divided into two types: Local Storage and Session Storage.
Session Storage variables on the other hand are only saved while the browser tab is open. The variables are also not shared with other tabs like Local Storage variables are. As soon as the tab is closed, the variables are deleted.
Both types of storage are useful in different circumstances.
To learn more about local and session storage, see this article.
Designating Storage Variables in CpExtra
CpExtra allows you to create an unlimited number of local and session storage variables.
To specify that a variable's value should be saved into Local Storage, put ls_ (l for Local, s for Storage) in front of its name. This is not case sensitive. The following variables would all be saved into local storage:
- _LS_Hello_World (you can put an underscore in front of its name to make it sort ot the top of the variables list)
On the other hand, if you would rather a variable be saved into Session Storage, put ss_ (s for Session, s for Storage) in front of its name. The following variables would all be saved into session storage:
As soon as those variable's values change, they are updated in their respective storage locations.
If in another Captivate project you define ls_MyVar or SS_YourVar (this is case sensitive), then you'll be able to see what value those variables were given in other projects in the course. You could also change the values of those variables, which essentially allow your modules to communicate back and forth with each other.
Note: You can use the xcmndFlushStorage command variable to clear local and session storage data.
Another tried and tested way for web pages to be able to communicate with each other is through the GET variable method.
Notice how first there is a ?. This question mark designates everything that comes after it as being GET variables. What are GET variables? Well see how after the ? it says search_query this is the name of a GET variable. After the name, there is a =. This tells us everything to the right is what the search_query variable equals. So in the end: search_query = Infosemantics.
Now click on the URL and then change the ending to say: ?search_query=Adobe
When you press enter, the page will refresh with a new list of videos relating to Adobe. Tacking these variables on the end of the URL is basically an easy way of sending information between one page and another.
CpExtra allows you to create user variables which can read the value of these GET variables thereby making them available for you utilize in Advanced Actions.
To make a GET user variable, just put get_ in front of its name (not case sensitive). So if you wanted to create a variable that would read the value of the search_query GET variable shown above, you should create a variable called: get_search_query
What if you wanted to use multiple get variables in your course? For example, you had the following variables (all of which are valid BTW)
When linking to the course, you could supply these variables values with a URL like so: www.example.com/index.html?username=Karen&userrole=manager&usergender=female
You can use any number of GET variables, as long as you separate each of their values with a & symbol.
What if in the URL we defined the value for get_username, GET_userrole but NOT _get_usergender? In that case, _get_usergender would retain the default value you set up when you defined the variable.