Skip to main content
Inspiring
November 19, 2019
Answered

Accessing functions & css classes of a webobject through an added JS file

  • November 19, 2019
  • 1 reply
  • 1591 views

I'm trying to acess elements inside of a web object that I've added into my Captivate project, through an external javascript file that I've linked to the index.html output file of my project. I'm pretty stuck on how to do this, but essentially I'd like to be able to control my webobject via the external JS file. 

 

I built my webobject with an html/css/js file structure and it uses css classes to toggle some animations. Is there any way possible I could call the function I created in my webobject from my external JS file? In my external JS file I made function for custom navigation back/forward buttons, and I'm hoping that once the user lands on the slide with the web object, the next button would then activate the function of my webobject, instead of taking the user to the next page, then once that's done it would move the user to the next page? 

 

I hope some of this makes sense, any point in the right direction would be greatly appreciated! 

 

This topic has been closed for replies.
Correct answer KeelyM

Thanks so much kdmemory!

 

I'm trying out this method - I've added my function inside of the webobject's JS page as such - 

window.myWebObjectFunction = function() {

// function stuff 

};

 

 

Then once placed into my Captivate project and the project is published, I attach a new JS file and I try to call the function like you have written out - 

 

window.frames[0].myWebObjectFunction();

 

Though it is returning as an undefined function in the console log. 

 

It's the only webobject on this slide of my project and I have it set inside of a function that listens for new slide enter, then inside of a function which listens for if the user is on the correct page, it's something like - 

 

var currSlide = cpAPIInterface.getVariableValue("cpInfoCurrentSlide");

function runByPages(){
if (currSlide==27){
window.frames[0].myWebObjectFunction();
}

runByPages();

 Would something about the way my WebObject is built be causing issues? My webobject is essentially a zipped file including an html, css, and js file along with any images that are used inside of it. Then I just drag and drop the zipped file into my Captivate project. 


An update - I wasn't able to get the WebObject function working when being called from an external JS file, so instead I added the function to an object in my Captivate project from the WebObject's JS page. So it looks something like this - 

 

window.parent.window.myCaptivateButtonVariable.addEventListener("click", myFunction);

 

Which so far, seems to be working! It's a pain, because any changes I need to make I have to go back and edit my WebObject files, zip them again, replace the WebObject in my Captivate file, then republish my Captivate file. But it's working!  

1 reply

Stagprime2687219
Legend
November 19, 2019

I do not work with external files but I do quite a bit of scripting within Captivate. Perhaps the issue here is the same.

Captivate will append a lower case 'c' to the end of the name of your Web Object.

 

For example - if I have a web object named   web1  I would need to address it as   web1c   in order to find stuff within it and do something to it.

At least this has been my experience. Perhaps you might try addressing it the same way with the external file.

I realize it is not necessaily the same but I did a series on sliders which are entered as web objects. I talk about using JavaScript to work with it here.
https://elearning.adobe.com/2018/05/set-variables-interactive-sliders-part-4-javascript/

 

Maybe you can get something helpful to get you going in the right direction with it.

KeelyMAuthor
Inspiring
November 19, 2019

Thank you! I'll take a look at the link and read through it!

 

I've been able to identify and access my webobject via the method you mentioned, appending a 'c' to the end of the ID. However, from there, I'm at a loss of how to access elements inside of the webobject? 

 

I've tried messing around with "children()" but I'm not much of a coder, I didn't get very far with that. 

 

For example, I have a div with the ID of "left" inside of my webobject, would it be possible to access that div from an external JS file after my Captivate project has been published? 

Stagprime2687219
Legend
November 19, 2019

Hunting down an item with an ID will use a hashtag.

For example...

 

$("#left").click();

 

would emulate a click on the object with the ID  'left'.
Based on what you have going on with your web object - things may get a bit more complicated but that would be the gist of it. Depending on what you want to perform may also require you to add that  c  to the child object.

 

$("#leftc").animate({left: "+=100px"});