Trying to call JavaScript function from "Add Hyperlink"

finaidmedia Community Member Posts: 3

I'm trying to call a JavaScript function from a hyperlinked text. I select the text, right click, and select "Add Hyperlink." In the window that pops up I select "Run JavaScript" from the "Commands" section and type in the name of my function.

When I publish the file, nothing happens when I click on the link.

As a workaround, I've been selecting "Run Action Group" and calling the JS function from an action within the group. It works, but it requires extra work that I'd like to eliminate.

Anybody have any idea why I can't call the function using "Run JavaScript?"



  • ssneg
    ssneg Community Member Posts: 1,466 ☆ Roadie ☆
    I just tested, yep, doesn't work. Looks like a bug to me. You should submit it to [email protected] and hope they fix it in a patch or next version.

    In the meantime, you can use:

    a) "Go to web address" action on the link and put "javascript:whatever()" in there (e.g. "javascript:alert("Don't click here!")") and it'll work.

    b) "Modify variable" action on the link with any variable (I would just create a dummy variable not used anywhere else) and put "javascript:yourcodehere()" in the Value field. It'll also launch your JS code.
  • finaidmedia
    finaidmedia Community Member Posts: 3
    Thanks, ssneg!

    I just tested the "Go to Web Address," method per your suggestion, and it works great. Less clunky than my workaround of putting the JavaScript in an action group and calling the group. This will save our team a lot of time when spread out over multiple course.

    I'll report the bug and hope the Lectora team takes care of it at some point.
  • timk
    timk Community Member Posts: 1,205 ♦ Idol ♦
    It does work for me, when

    1. Putting the function into the "Run javascript" action itself

    2. Putting the function into an HTML extension on page level

    3. Putting the function into an HTML extension on title level

    Tested it with IE, FF, Chrome

    How exactly did you set it up?