Javascript to generate Lectora action??
June 24, 2017 12:00 AM
Hello,
I have some JS which generates and displays text to a text block. Amongst other things, this bit of code generates hyperlinks. These hyperlinks seem to work correctly and I would like them to trigger JS functions (onclick etc...). I think that will be ok. However, I wonder if a hyperlink can also trigger Lectora actions. I suspect the answer is "no" but I thought I would ask anyway.
cheers
andrew
Discussion (3)
Actually, triggering a JS function is not ok :(.
As a followup - if I place the following piece of code in a JS action, a string with a link is published correctly to a text box. If I click on the link nothing happens. If I substitute a URL for the onClick, the URL works fine. It seems that the function is not found, but where to put it? I tried an HTML object (head of file) bu that did not work either.
Code below
function MyFunction(x, y) {
alert ("In MyFunction= " + x*y);
return(x*y);
}
mystring = 'link text'; // This is published correctly (below) but does nothing when you click the link -- The OnCLick works fine in a normal html page
var message = document.getElementById("text4908");
message.innerHTML=mystring; // This publishes a URL in a textbox - published correctly but nothing happens to call the function - a URL instead of a function works fine in Lectora
yourstring=MyFunction(9,12);
alert(yourstring); // The function call is ok
Solved it actually - had to place the script into a html extension at the top of the title. Only way it could be found by the onclick in the calling link.
Thanks for the upvote - now I notice that the code I published is gibberish - it was missing the key element, the function call... sorry :(
undefined
Discussions have been disabled for this post