Accessing variable in embedded hype file from outside html document

Hi. I exported as html5 but now need that html file to access a variable inside the embedded hype. Is that possible? I have an html document with 5 tabs. In each of those tabs is a separate embedded hype file where the user must click on the right answer. I just found out that i need to track a variable in each of those iframe embeds. If the user has answered all 5 of the embedded questions, i will have an ‘activity completed’ div appear. My javascript logic will be when the user clicks the right answer in the hype files, a counter variable will be increased. If the counter is equal to 5, that means all 5 correct answers have been selected so now i can show a completion div in the main html file. thanks.

please rethink the iFrameapproach if possible as it complicates processes ... but anyhow @MaxZieb wrote an extension to solve your problem :slight_smile:

I wish i hadn’t done it that way to start with but i didn’t foresee needing to accomplish what i need to. Now i must get things in a jiffy so no time to restructure this activity. Thanks for a speedy answer, i’ll look at what you attached.

I’ve been trying to understand how to implement this but i’m finding it difficult to understand the example.

In a simple case you can access parent iframe global variables/functions like:

parent.window["myGlobalVar"] += 1;

However depending on your setup there might be security issues accessing the parent, and a parent cannot access a child so you might be out of luck with this approach. The more thorough approach is to use javascript’s postMessage. There are examples on the forums; the code for this method isn’t simple. The Hype GlobalBehavior extension makes use of it, so may be the best option still!

1 Like

I see. I will document that information for the future. In this case i need to do the opposite of accessing the parent frame. I need the parent frame to read a variable in the child. I’ll read up about postMessage and the GlobalBehavior. Thanks Jonathan.

1 Like