{"id":633,"date":"2017-08-18T05:32:51","date_gmt":"2017-08-18T05:32:51","guid":{"rendered":"http:\/\/360elearning.com\/blog\/?p=633"},"modified":"2017-10-14T12:05:43","modified_gmt":"2017-10-14T12:05:43","slug":"embed-javascript-in-articulate-storyline","status":"publish","type":"post","link":"https:\/\/360elearning.com\/blog\/embed-javascript-in-articulate-storyline\/","title":{"rendered":"How to Embed Javascript in Articulate Storyline"},"content":{"rendered":"<p>We are massive fans of Articulate\u2019s Storyline product here at <a href=\"http:\/\/360elearning.com\">360elearning Company<\/a>. It\u2019s now our tool of choice when developing eLearning modules. One of the fantastic features is the use of triggers and in particular Javascript triggers by which we can embed Javascript in <a href=\"https:\/\/articulate.com\/360\/storyline\" target=\"_blank\" rel=\"noopener noreferrer\">Articulate Storyline.<\/a><\/p>\n<p>Now we are not Javascript experts, however that doesn\u2019t stop us, as we have found many friends out there in the eLearning community who are more than happy to share Javascript code they have written. We have spent hours searching the web and the Articulate forums for pieces of code to make eLearning projects more exciting and interactive, and we thought we would share them with you.<\/p>\n<p><strong>1. Print the current window<\/strong><br \/>\nThis piece of code will print the current window to your nominated printer. A few people have queried whether it is possible to change the page settings (i.e. from portrait to landscape) unfortunately you are unable to.<\/p>\n<p>window.print();<\/p>\n<p><strong>2. Popup message<\/strong><br \/>\nThis piece of code will create a popup message to your course. As you can imagine this can be used in a number of ways, but one of the most obvious is if you want to create a message that the learner must view all areas before the next button will work.<\/p>\n<p>window.alert(\u2018You must explore all areas before proceeding.\u2019);<\/p>\n<p><strong>3. Popup message with variable<\/strong><br \/>\nThis piece of code is a slight variation on the above code. This version will also pull through a variable (if you have one) into your message.<\/p>\n<p>var player = GetPlayer();<br \/>\nalert(\u201cWelcome back, \u201d + player.GetVar(\u201cFirstName\u201d) + \u201c.\u201d);<\/p>\n<p><strong>4. Save variables to a text file<\/strong><br \/>\nThis piece of code will save any variable a learner has entered to a text file.<\/p>\n<p>var fso = new ActiveXObject(\u201cScripting.FileSystemObject\u201d);<br \/>\nvar s = fso.OpenTextFile(\u201cC:\\\\Test.txt\u201d, 8, true, 0);<br \/>\nvar name = player.GetVar(\u201cTextEntry\u201d);<br \/>\nvar email = player.GetVar(\u201cTextEntry1\u201d);<br \/>\ns.WriteLine(\u201cEmail: \u201d + email);<br \/>\ns.WriteLine(\u201cName: \u201d + name);<br \/>\ns.WriteLine(\u201c==========\u201d);<br \/>\ns.Close();<\/p>\n<p><strong>5. Generate a Random Number<\/strong><br \/>\nThis piece of code will generate a random number. The example below will generate a number between 1 and 10.<\/p>\n<p>var randomnumber = Math.floor((Math.random()*10)+1);<br \/>\nvar player = GetPlayer();<br \/>\nplayer.SetVar(\u201crandnum\u201d,randomnumber);<\/p>\n<p><strong>6. Send a completed result to your LMS<\/strong><br \/>\nThis piece of code sends a completed result to your LMS. The reason this is a handy little code is that you can set up a \u201cpre-test\u201d as well as a \u201cpost-test\u201d and no matter which one is attempted (and passed), a result will be sent to your LMS that the course is completed.<\/p>\n<p>var lmsAPI = parent;<br \/>\nlmsAPI.SetScore(90, 100, 0);<br \/>\nSetStatus(\u201ccompleted\u201d);<\/p>\n<p><strong>7. Pull a learners name from the LMS in Storyline<\/strong><br \/>\nThis piece of code pulls a learners name from the LMS straight into your Storyline project.<\/p>\n<p>var lmsAPI = parent<br \/>\nvar rawName = lmsAPI.GetStudentName();<br \/>\nvar nameArray = rawName.split(\u201c,\u201d)<br \/>\nvar niceName = nameArray[1] +\u201d \u201c+nameArray[0];<br \/>\nvar p = GetPlayer();<br \/>\np.SetVar(\u201cusername\u201d,niceName);<\/p>\n<p>These are the ones we have come across so far, we will add any more that we find. If you have any that you would like to add, share with us.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are massive fans of Articulate\u2019s Storyline product here at 360elearning Company. It\u2019s now our tool of choice when developing eLearning modules. One of the fantastic features is the use&#8230;<\/p>\n<p><a class='more-link' href='https:\/\/360elearning.com\/blog\/embed-javascript-in-articulate-storyline\/'>Read More <span class='screen-reader-text'>How to Embed Javascript in Articulate Storyline<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":641,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[176,5],"tags":[190,189],"class_list":["post-633","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aritculate","category-storyline","tag-articulate-storyline-2","tag-javascript","excerpt"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/posts\/633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/comments?post=633"}],"version-history":[{"count":6,"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/posts\/633\/revisions"}],"predecessor-version":[{"id":738,"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/posts\/633\/revisions\/738"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/media\/641"}],"wp:attachment":[{"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/media?parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/categories?post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/360elearning.com\/blog\/wp-json\/wp\/v2\/tags?post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}