Forum

Executing a js callback in a second iFrame

12 July 2017 04:47
Hi Guys,

I've got two iFrames in my parent HTML page; One contains the B4W app and the other contains HTML content that I'd like to affect from the JS.

I've seen a topic on here about iFrame communication, but I can't seem to find it.

My function looks like this:

var loc = "Menu1.html";
   }
    
    function changeFrame_cb(in_params, out_params) {

        console.log("changeFrame_cb was called!");
        parent.document.getElementById('myFrame').setAttribute('src', loc);
    }


The console reports 'Can't find variable: loc'

The 'loc' is in the same directory as the B4W HTML aswell as the parent (index.html)

Any ideas?

Thanks
12 July 2017 10:06
Not sure since I can't see the rest of the code but it might be a scope problem. Try this:
    
    function changeFrame_cb(in_params, out_params) {
        var loc = "Menu1.html";
        console.log("changeFrame_cb was called!");
        parent.document.getElementById('myFrame').setAttribute('src', loc);
    }
13 July 2017 05:11
Yeah, I actually figured this one out on my own. Declaring the variable within the function worked a treat. Thanks again.

C
 
Please register or log in to leave a reply.