Pass URL

tomtom
Community Member Posts: 27 ♪ Opening Act ♪
I have a url test.com?userID=1111&key=111, which launch the lectora lesson
I neeed to be ABLE TO pass userID and the key to lectora lesson
I neeed to be ABLE TO pass userID and the key to lectora lesson
0
Comments
-
wheels Community Member, Administrator, Moderator, Rockstar Manager Posts: 504 eLearning ROCKSTAR Admin TeamYou can add a Run JavaScript action and get the query string parameters using JavaScript.
See here for required JavaScript:
https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
Then you can create user variables in Lectora, MyUserId and MyKey.
In your JavaScript you can set those variables using the set method:
(variable JavaScript names can be found in the variable manager)
VarMyUserId.set( idParam );
VarMyKey.set( keyParam );
Then you will have those values available in Lectora variables to use in your course.1 -
Thank you. I have followed the instruction and I got this far.
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
var userkey1 = getParameterByName('userKey');
var sessionUnitKey1 = getParameterByName('sessionUnitKey');
alert(userkey1 );
I have created 2 variables in Lectora userkey and sessionunitkey
The problem is to set the variable for Lectora .
when I do this I get an error message
Varuserkey.set( userkey1 );
Varsessionunitkey.set( sessionunitkey1);0 -
The error message that I am getting is : ReferenceError Varuserkey is not defined0
-
You have to use the variables in a Lectora action. Otherwise Lectora believes they aren't needed and doesn't initialize them. If you want to use the variable later on the same page just create this action first. You can also add a group on title level with 1 action "Reset all variables". This action uses all variables at once, just don't Run this action group if you don't want to reset the variables.0
-
I want to store the variable in lectora so I can pass it later when I submit the test to a processing page. So I got the javascript to work. Now in Lectora what do I need to do0
-
Add a group on title level. Add one action to the group "Reset all variables".
This should solve the "Varuserkey is not defined" issue.1 -
On the title level I am also setting running my JS file . What should happens first. And can I create a group and reset variables first and then run the JS or reverse the order in the same group?
0 -
The action in the group is not meant to be executed, it only exists to make Lectora initialize all variables, i.e. sequence is not relevant. Just put it there, your JS won't be influenced.0
-
My variables does not get set. have attached my awt file I do not know what I am doing wrong. Please advise0
-
The awt is not in the zip.
It seems you've put the "function getParameterByName(name, url) " into a "Run javascript" action. That's not advisable because the action is turned into a function again. It's better to put it into an HTML Extension (Insert > Add Web Object > HTML Extension), change the type to "Header Scripting". Click Edit, enter the function code and remove it from the action, i.e. only the function, leave the rest.
0 -
I
will try this0 -
-
There are two decisive typos in your code:
"Varuserkey is not defined", because in Lectora there is no variable called "userkey". The name of your variable is "userKey".
When using the function you need to pass the correct values:
You wrote your url looks like this:
test.com?userID=1111&key=111
To "getParameterByName(name,url)" you need to pass the name of the parameter, which is "key" not "userKey". The other parameters name is "userID", exactly like it is spelled in the URL.0 -
I am trying to execute that code now. I does not always work. The JS does not seems to trigger on the page show. I am puzzled . Please help0
-
Are there any javascript errors in the console? I'm not sure why it would work sometimes but not always ...
I tested the code above and it seemed to work.
0 -
What I found If I add the content page before. So it will be the first page then nothing get stored. Is there a way to only stored upon arrival basically on the first page and then carry through the entire lessons. My lesson will be 100+ pages plus a quiz0
-
You can add a condition to check whether the variable already contains a userKey, i.e. check whether it contains a value that is not the initial value of the variable, e.g.
Run Javascript Only if "userKey" Not equal to "0".0 -
So You Wanna Be An eLearning ROCKSTAR?
Categories
- 4.4K All Categories
- 35 ✫ Announcements
- 5 ✪ Contests
- 33.6K eLearning Brothers® Products
- 33.2K Lectora®
- 31.3K Lectora Discussions
- 1.9K Lectora Feature Requests
- 56 Lectora User Groups
- 2 AssetLibrary™
- AssetLibrary Discussions
- 2 AssetLibrary Feature Requests
- 221 CenarioVR®
- 122 CenarioVR Discussions
- 99 CenarioVR Feature Requests
- 2 Rockstar Learning Platform®
- 1 Rockstar Learning Platform Discussions
- 1 Rockstar Learning Platform Feature Requests
- 4 Off-the-Shelf Course Library
- 3 Off-the-Shelf Course Library Discussions
- 1 Off-the-Shelf Course Library Feature Requests
- 108 CourseMill®
- 101 CourseMill Discussions
- 40 ReviewLink®
- 28 ReviewLink Discussions
- 12 ReviewLink Suggestions
- 1 The Training Arcade®
- 1 The Training Arcade Discussions
- The Training Arcade Feature Requests
- 7 Additional Learning Products
- 2 Adobe®
- 2 Articulate®
- 1 Camtasia®
- Docebo®
- 1 iSpring®
- 1 Microsoft® PowerPoint®
- 892 All Things eLearning
- 3 Course Development Showcase
- 1 eLearning Brothers® Downloads
- 1 Compliance Training
- 5 eLearning Development
- eLearning Game Design
- 7 Instructional Design
- 544 Learning Management System (LMS) Integration
- 2 Mobile Learning
- 2 Visual Design
- 323 Web Accessibility
- 1.2K ♪ The Green Room
- 3 ♡ Community Feedback
- 7 Community Tips