Target Web Object
Nov 28, 2018
On a slide I need to put two web objects. I also have some JavaScript which is meant to target one of the web objects. How can I tell one web object from another? I've been trying document.querySelectorAll("iframe")[0] but if I make some edits and I change the order then this can't work.
I tried adding some Accessibility > Alternate Text but when I look at the published content the Web Objects iframe nor anywhere else has the Text.
21 Replies
What are you trying to change about the web object? I think the only really supported method is sending and receving variables values between the Storyline player and web objects.
I need to query the "state" of the web object.
I don't quite follow. To send a variable value to a web object I must have some way to identify the web object, don't I?
Anyhow can you please tell me how to send/receive variable values to/from a web object?
Sorry, I know how to send data from a web object to storyline. What I don't know is how to target a web object to send it data from storyline.
To do this, I run javascript within my web object that checks the value of the Storyline variable every 1 second or however often I think I need to. I have some sample code that I will try to find tomorrow, if you think that solution will work for you.
I don't know. Having to poll the parent from a web object doesn't sound like a robust way to do this but if there's no real other way then, yes, please send through the code you have.
To target a function in a Web Object, I use:
window.frames[0].frameElement.contentWindow.NameOfFunction();
I have attached a sample project for you to take a look at where an input value is passed to the Web Object.
I like Russell's solution better, it just might not be an officially supported solution, just in case the underlining html generated by Storyline could somehow change to make it no longer work.
Here is some sample code to check a Storyline variable from within a web object. This will check the value of a player variable called dnd everything 1000ms (1 second). If dnd equals true then some code is run, right now just setting another player variable. This example might not appear to make sense because I removed some other lines in the if statement that were specific to the project it went to. Let me know if you need any help implementing this.
Thanks. Does Storyline not use iframes for anything else? I haven't tested every type of element but I'm concerned if, say, videos are put in an iframe then frames[0] might be the wrong iframe.
I guess I need to clear the setInterval at some point but I get the gist. Thanks.
Yes, you can clear the setInterval if you no longer need it running.
Hi,
If I understood correctly you want to target specific iframe. I have prepared two examples. One is for webparts from the Internet (external) one is for internal ones (your html file).
Here is a output where you can test the code in the console:
https://elearnigujse.s3.amazonaws.com/webobjects/story.html
In the attachment there is txt file with the script.
Let me know if something is unclear.
Przemek
Nice solution Przemysław. Does this also work well for web objects embedded from local html files?
Hi Michael,
It is in the second part of the txt file.
You provide only name of the html file in my example it is (var targetedWebObjectUrl = "form.html" or var targetedWebObjectUrl = "test.html")
I have included additional step to decompose the full url and compare only the last part:
tempSrc = webObjects[i].src.split('/')
if(tempSrc[tempSrc.length - 1] == targetedWebObjectUrl)
I have updated the code file because previously I put "index.html" as a compare criteria but I had two local files titled: form.html and test.html for existing web object. That's why it couldn't find any with index.html.
Thanks to everyone for their help. It put my on the right road and I have everything working as I hoped it would be.
Here is the code that I have used if I didn't know which frame to target.
for (i=0; i<window.frames.length; i++) {
try {
window.frames[i].frameElement.contentWindow.NameOfFunction();
i = window.frames.length;
}
catch(err) {}
}
Can I get in touch with you just to get advice as to how to get this far, please? I have to insert some software demos into my course and am totally stumped.
Hey Ben,
Just wanted to pop in and share that you are welcome to reach out to the user directly via the 'Contact Me' option on the user profile if you do not hear back soon.
Hey Ben, I'm not sure if you're replying to me but if you are, ask away.
Basically you need to work out
I've set my profile so that people can't contact me directly. If you want something from me please ask in this forum so that everyone can benefit from the exchange.
So do you have any specific questions for me?
This discussion is closed. You can start a new discussion or contact Articulate Support.