Explore the community Forums Lectora Lectora Questions & Answers HTML Extension, Javascript, Will not add to page

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #411022 Score: 0
    Profile photo of Benjamin Slack
    Benjamin Slack
    Member
    beginner
    intermediate
    picture perfect
    friend finder
    curious george
    wise owl
    1 pt
    @bslack5361

    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

    #411037 Score: 1
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    251 pts
    @timk

    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 =” 😉

    This post has received 1 vote up.
    Attachments:
    1. AddJS.zip
    #411057 Score: 2
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    106 pts
    @mnotermans5114

    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.

    This post has received 2 votes up.
    #411107 Score: 0
    Profile photo of Benjamin Slack
    Benjamin Slack
    Member
    beginner
    intermediate
    picture perfect
    friend finder
    curious george
    wise owl
    1 pt
    @bslack5361

    This is exactly the direction I was looking for. Thank you very much for this quick overview. Greatly appreciated.
    -B

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.