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
Michael Anderson

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.

var storylinePlayer = parent.GetPlayer();
setInterval(updateDND, 1000);
function updateDND() {
var dnd = storylinePlayer.GetVar("dnd");
if dnd{
storylinePlayer.SetVar("dndComplete",true);
}
}
Przemysław Hubisz

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

Przemysław Hubisz

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.

 

This discussion is closed. You can start a new discussion or contact Articulate Support.