HTML Extension, Javascript, Will not add to page

bslack5361
bslack5361 Community Member Posts: 4
Greetings folks.

I'm fairly new to Lectora, but I have a CS background. I'm attempting to dip my toes in, investigating how to add script to a title to give custom functionality. To that end I made this little toy function.
<script>
/*
 * !CODE ADDED HERE!
 */

// start slack_lec_helpers.js
function benAssignClass (object_id, class_id){
	var div = document.getElementById(object_id);
	var spans = div.getElementsByTagName("span");
	var i = 0;
	for (i=0;i<spans.length; i++){
		spans[i].class = class_id;
	}
}
// end slack_lec_helpers.js
</script>


I placed it in a js file and tried to embed it via HTML Extension. I then called the function from an action script. However, the code doesn't show up on the page where the HTML Extension says it should be when I preview it. I've tried Top of page script, header scripting, and bottom of the page. No code gets inserted, no js file gets sourced. I've tried in script tags and sans script tags. I've tried script in comments and without. I've read a half dozen tutorials that say this is the way to go about things, but they don't seem to work here. Any ideas why my code is not getting added to the title? Thanks in advance for the assist.

-B

Comments

  • timk
    timk Community Member Posts: 1,205 ♦ Idol ♦
    There are several ways to add custom JS. I've added a sample that contains 4.

    And of course the code needs to be correct: it should be ".className =" instead of ".class =" ;-)
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    And next to the things Tim mentioned there is quite a difference in using Javascript in Lectora Online compared to Lectora 16/17. I dont know yet whether Lectora 18 is similar ( i do expect that it will be ) to the way Lectora Online handles HTMLnames etc. for custom scripting. Will do some tests with that as soon as possible.

    Seamless play also dumps all pages into a separate iframe, so targetting elements on a page is quite different then too.
    If you check my shared content you for sure find samples where i explain the differences better.
  • bslack5361
    bslack5361 Community Member Posts: 4
    This is exactly the direction I was looking for. Thank you very much for this quick overview. Greatly appreciated.
    -B