Explore the community Forums Lectora Lectora Questions & Answers Trigger Lectora event from JavaScript Reply To: Trigger Lectora event from JavaScript

#398459 Score: 0
Profile photo of Stan Miller
Stan Miller
LUC16 Attendee
wise owl
curious george
friend finder
LUC17 Attendee
38 pts

<span class=”handle-sign”>@</span>zliquorman1276, I actually do know how to set a course completed. My problem was (note past tense) triggering an action to do so from the JavaScript inside an iframe. As noted in reply to Tim, running an action group from a JavaScript within an iframe doesn’t work because the script doesn’t have access to objects on the parent document.

However, it does have access to a header script on the page that contains the iframe, and I can call a function in that header script from within the iframe. So:

  1. An action group with actions to hide the iframe, show the “you’re done” message and set the course completed.
  2. A header script with a function that runs that action group. (Thanks for that snipped, Tim!)
  3. A line in the script in the iframe calling parent.function()

I am intrigued by this line, which could prove very helpful for other situations:

you could trigger Lectora actions via Javascript directly

Got a code snippet for that?