Forum Discussion

MartinRoss's avatar
MartinRoss
Community Member
11 years ago

Link to a URL held in a variable

Has anyone been able to create an onscreen link to a webpage whose URL is held in a variable? I can't get my javascript to work.

My current attempt goes like this:

var player = GetPlayer();
var url = player.getVar("google"); // google is a text variable containing "http://www.google.com"
var win = window.open(url)

 

Any ideas?

12 Replies

  • NaserSedghi's avatar
    NaserSedghi
    Community Member

    Hi Mike, You would need to make a .js file assigning variables to the URL addresses. For example: 

    Add the .js file to the story_content folder of your published story.

    var var1 = "https://the address";

    var var2= "https:// ...";

    Modify the story.html file to contain the script for your .js file (I have have named it LinksList.js). The code below should be added anywhere between <head> and </head>:

    <script LANGUAGE="JavaScript1.2" SRC="story_content/LinksList.js" TYPE="text/javascript"></script>

    The index_lms.html should be modified the same way.

    Modify imsmanifest.xml by adding the location of your .js file to the resources section of the file:

    <file href="story_content/LinksList.js" />

    Define a variable in your story (I have defined it as Lecture1).

    Use a run javascript trigger to connect the story variable to the variable you have defined in your .js file:

    var player = GetPlayer();
    player.SetVar("Lecture1", var1);
    var url = player.GetVar("Lecture1");
    var win = window.open(url);

    I hope that you find it helpful.