Using one Captivate 8 file to password protect access to another Captivate 8 file.
The user logs in with their user name, which is assigned to a variable $$username$$.
Can I somehow transfer this user name to another Captivate file which is opened by the first file?
Hope the question is clear.
Thanks so much.
You can do this using URL parameters or LocalStorage.
You can set/store an item to storage like this:
In the other course, you can retrieve the value like this:
This assumes you have a Captivate user variable called "StudentName" in both Captivate projects.
I left out that the first bit of code would probably be executed on a text entry box's submit button.... or any button.
The second bit of code could go on slide entry of the first slide of the other captivate project.
Oh, so you append it to the URL in the outgoing Captivate file?
So if the url I use is, say, http://www.website.com/quiz.html,
I can make it: http://www.website.com/quiz.html/window.localStorage.setItem('StudentName', window.cpAPIInterface.getVariableValue("StudentName"));
And to retrieve the value, where would I add the second string?
Thanks so much, Jim!
I've been struggling with this for a few days, so perhaps you can advise,
Leaving the first page where the User logged in, the UserName was snagged
to pick up the UserName. I put this on the "On Enter" of the page.
The problem is that I also have to have a conditional statement...If
UserName = joeschool (for example) then assign the appropriate google
script for the widget.
conditional script assignment in a conditional advanced function? It
seem I can only do either a standard action OR a conditional action?
thanks so much.
On Wed, Dec 17, 2014 at 9:00 AM, Jim Leichliter <email@example.com>
This is my first post in any Adobe forum, and hopefully someone will be able to help.
The task I need to do is exactly as laid out in Jims post...store some data for use by the next project.
I have created a project with 1 slide.
I have created a variable called StudentName with a Default value of "peter" (without quotes)
I have put in the following script:
// Show an alert to prove the code is running.
//Show an alert to prove my variable has the Default data in it.
//Store the data from my variable for use by the next project.
//Show an alert to prove the code got to here.
I have used F12 to run it.
The alert for "start" works
The alert for my StudentName variable works.
BUT, the alert for "end" does not show.
I guess that the code for storage has caused some sort of error and the script has stopped.
I commented out the line of code
and all three alert boxes are shown.
I have published the swf file and placed in on our internal server, but still no luck.
I have not attempted a script to retrieve the varaible yet, as Im not certain it is being stored.
My question is: Please can someone tell me what has gone wrong with what should be a simple bit of script?
Hi Peter and welcome to the forums. Here's a few things to check:
var sName = window.cpAPIInterface.getVariableValue("StudentName");
window.console.log('Set Student Name In Local Storage');
Try the above ideas and if they don't work, share your project and I can have a look.
All is good.
Your explanation was clear and your code worked, thank you.
I had to play around an awful lot... and got help from a passing techie, but it works
One thing I discovered is that our Antivirus (McAfee) hinders the usage of any folder with the word 'temp' in it.
As Captivate uses a temp folder when the F12 key is pressed, I was running into problems there, even though I did not know it until the tech people told me.
(When I enquired whether this 'temp' setting could be changed in the anitvirus the answer was a very loud "No !")
So the only way I could test it was to run it from the proper server each time.
Once again, thank you so much.
@Peter: Nice work! Glad you stuck it through to see a solution!
I tried the solution Jim and it worked perfectly. Is there a way of transferring data so it's not stored locally on the machine. For example in shared device circumstances.
How does the URL parameters work?
Ideally it would be great to store the data in the browser, then when it's closed the data would be wiped.
I'm not sure if that's possible?
localStorage can be cleared when the browser is closed. You use sessionStorage instead of localStorage.
Both localStorage and sessionStorage are stored in the browser. In the way that each browser stores it in it's own location and the setting are done in the browser.
URL parameters append data to the URL, but the page that sends the parameters needs to open the second page.
The reason I was asking is I thought local storage stored data on the device itself?
For example we have set up a simple score variable that loads/saves across different modules in the LMS. However if a different user loads a module on the same device and loads the score it will just pull in the data from the last person's save.
I figured ways around it. But wanted to see if there was another storage command that could be used that would be wiped when the browser is closed, just for more flexibility when designing.
I'll give sessionStorage a test out and see how that works.
Local Storage DOES store the data on the device. But if your users are all using the same user login account then that would explain why you're seeing this behaviour. Is that the case?
Yeah I was logged into windows... but testing using different people's log ins on the LMS.
So if someone else logged into the machine it wouldn't happen? So it remembers it based on the log in to the machine?
It's related to the user profile on the machine, not the LMS. So if you were using the same profile on the PC, then the browser is storing all the local storage data in the same place.
Log into the PC as someone else and try it again.
You can a prepend different information to the storage to allow different users on the same computer. Below is an example using the course name derived from the Preferences/Project/Information/Project Name: field (HTML5) and the cpQuizInfoStudentName variable.
var sID = window.cpAPIInterface.getVariableValue( 'cpQuizInfoStudentID' );
var pID = cp.model.data.project.pN;
var lessonStorage = pID + '.' + sID ;
if ( typeof( Storage ) !== 'undefined' && window.location.protocol.indexOf( 'http' ) != -1 )
localStorage.setItem( lessonStorage, JSON.stringify( yourDataVariable ) );
I thought I'd continue in this thread as it's about the same subject rather than start a new one.
I tested it in Captivate by previewing in the browser (in Safari on a Mac) and it works as long as I come back to the project file and preview again in the same day.
However, I thought it would have worked still no matter how long I left it. Admittedly, I've yet to publish the swf so I've done that and tested it in Safari and Chrome and will leave it a couple of days before accessing it again and 'loading' the variables.
However, the good news is that our users don't use Macs they're all on windows based machines... I fired up the test file I create a couple of months go in Internet Explorer (The default browser our users have). This only has a single variable that loads/saves and it had been hosted on the LMS and it worked perfectly loading up the score I had saved a couple of months earlier.
I'm also going to test to the published swf with 3 variables on the windows machine to see if it works on there.
So I guess what I'm asking is whether
a) previewing in captivate should make the local storage behave any differently?
b) Whether it's an issue with Safari or specifically using a mac?
c) Whether it's an issue with the coding, although this seems the least likely as it does save/load the variables if I access it multiple times in the same day/while the machine is on. I have gone back into Safari and checked all my history etc is still there as I know the local storage gets wiped when clearing the browser cache.
Answers to your questions.
a: Yes, previewing in Captivate would certainly effect the way that local storage would work. Think of local storage information as being put into little boxes, and none of these boxes can touch. Every browser has its own set of boxes (local storage can't be transferred between browsers) and every website has its own box (google.com can't share local storage data with adobe.com). When you preview in Captivate, you are most looking at a local host server generated by Captivate. That would have it's own little box. Captivate at certain points (it's hard to say when as we're not part of the development team) resets the local host server. At which point the local storage data would be lost, or at least no longer accessible.
So if you want to test local storage with any kind of consistency, you need to be publishing your Captivate content and viewing it on your own local host server.
b: Local Storage is quite a well established standard in browsers. I have never heard any trouble with MACs or Safari. Certain minor versions of Internet Explorer however have bugs with it. Make sure your version is up to date.
Thanks for your answers Widget King I really appreciate it.
So I've gone back to my working file which only has the one variable to save/load. To further test it.
As I mentioned in my last post, in the LMS it works fine, when uploaded as a SCORM package.
I did some further testing and noticed that it won't work if it's a SWF by itself, no matter where it's hosted. I also published the SWF file zipped up and hosted it on a company team site, as opposed to the LMS, and again it wouldn't work as in order to access the SWF file I had to unzip it.
Hi, unless I'm missing something, this can only work if the same user is using the same machine to access the file. I was thinking of setting up something like this:
File 1 asks whether they're Team 1 or Team 2 - based on their response it opens File 2.
File 2 is for Team 1 who has data for their game (on Team 1's one computer as it's being completed through Breakout Rooms in a VILT setting)
File 3 if for Team 2 who has data for their game (on Team 2's one computer as it's being completed through Breakout Rooms in a VILT setting)
File 4 is for displaying the results of the game while it is still being played. It would contain the variable passed from File 2 and File 3 and it would be opened by the trainer as a leaderboard.
Is this doable or is this something that has to be done through the LMS?