How do I save a value in a cookie in the user's browser to be accessed in another session?
You can use a Lectora variable to store a value as a cookie in the user's browser. This value can then be accessed in a future session by this same user.
If you want to save a value as a cookie in a user's browser, the Lectora variable feature can be used. Here are the steps to use a Lectora variable to save the value as a cookie.
- Create a user variable in the Variable manager. Click on Tools, then Variables to open the Lectora Variable Manager.
- Click on the Add button in the lower left of the Variable Manager window.
- Enter a unique name in the Variable Name field
- Set an initial value if you want one
- Choose the check box next to "Retain variable value between sessions.
- Click the OK button midway down the page to save this variable.
- Click the Close button to close the Variable Manager window
- You can use a Lectora action to add data to this variable.
- Modify Variable Set Equal To will save the data in the Action Value field to the variable.
- Modify Variable Add to Variable will append the data in the Action Value field to the variable
- When you want to access the data in the variable, you use the VAR(variableName) function, where "variableName" is replaced by the name of the variable you created in section 1 above.
This functionality will work in "Preview in a browser", and when you publish to HTML and use the Preview button to test the saving of the data in the browser cookie.