Skip to main content
Participating Frequently
October 8, 2017
Question

Captivate Javascript and Cookies

  • October 8, 2017
  • 1 reply
  • 801 views

Hi all,

How do i go about reading a browser cookie from within a captivate project using Javascript? The need arises because I have a website with user login. Based on the type of user logged in, I will write a cookie to contain user type, i.e. 1 or 2 etc.

I would like to read this value from the cookie within a Captivate project so that I can use it in a captivate variable to determine what is shown in the project among other things.

The workflow (i'm guessing) is to first create a cookie in the browser. Let's call it usertype=1 etc.

In the Captivate project create a variable called usertype. Then use javascript to read the cookie and update the value of Captivate variable with cookie value. Then i have a usable variable in captivate for use in advanced actions etc.

Any guidance would be greatly appreciated.

Thanks

    This topic has been closed for replies.

    1 reply

    RodWard
    Community Expert
    Community Expert
    October 9, 2017

    You'd normally need to learn how to do some JavaScript programming to achieve this.

    But if your intended published output is HTML5, you can achieve the same result without programming by using the CpExtra HTML5 widget.  It allows you to persist data in the browser's local storage and retrieve it later again.

    See the explanation in the CpExtra Help Files here:

    http://www.infosemantics.com.au/adobe-captivate-widgets/cpextra/help/data-persistence

    MufakkirAuthor
    Participating Frequently
    October 9, 2017

    Thanks for your reply, but i dont think you have understood my requirement. I am not in need of data persistence. That can be done with localstorage without CpExtra.

    I need Captivate to read data stored in a cookie which the website sets NOT data set by Captivate. In other words, I need browser to captivate and not captivate to browser or captivate to captivate, if that makes sense.

    Legend
    October 10, 2017

    As Rod stated, you will need to program this using JavaScript.  Here's an example of reading a cookie value.  Here's some info on basic cookie creation, reading and deleting cookies.

    One of the best tools to use for looking at cookies is your browser's Developer tools.  I typically use Google Chrome's developer tools to view the cookies (or LocalStorage) for a given site.  Knowing the name and structure of the cookie will help you parse out the necessary info.  If you need help doing this, please PM me and we can work something out.

    Best,

    Jim Leichliter