We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Can V3d receive window.postMessage events?

Home Forums General Questions Can V3d receive window.postMessage events?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #31520
    grimmy
    Customer

    I am told this is a good way to communicate between iframes and the current page but I cant find anything in puzzle to listen to such events.

    Is there a way?

    Thanks

    #31534

    Hi,

    there is no such puzzles yet, sorry, but you can implement this with JavaScript and link with the Puzzles as show here:
    https://www.soft8soft.com/docs/manual/en/introduction/Using-JavaScript.html

    Chief 3D Verger | LinkedIn | Twitter

    #31551
    grimmy
    Customer

    Thanks for this but I tried a few variations and cant get it to work. Maybe my situation is slightly different to those described in the manual(?):

    I have a parent app which has the verge3d app embedded as an iframe. I want the parent app to perform some function on the v3d<iframe>. Im using postMessage from the parent app to send something to the iframe but I’m just not sure how the v3d iframe picks up the message.

    #31553
    grimmy
    Customer

    I have the solution for anyone wishing to try the same thing:

    In my parent app I send the message like so:

    var myIframe = document.getElementById('v3d_iframe');//Note:I have set the ID of my iframe to v3d_iframe
    
    myIframe.contentWindow.postMessage('myMsg', '*');

    In my awesom_application.js script I make a message listener like so:

    window.onmessage = function(event){
        if (event.data == 'myMsg') {
            console.log('myMsg Message received!');
        }
    };

    However I still don’t know how I would go about sending more data (variables) to the v3d window…if anyone has any ideas let me know..

    #31557
    grimmy
    Customer

    In order to send a bunch of data to the v3d iframe you can do this:

    Parent:

    var myIframe = document.getElementById('v3d_iframe');
    myIframe.contentWindow.postMessage(
        {
            event_id: 'myMessage',
            data: {
                v1: 'value1', 
                v2: 'value2'
            }
        }, 
        "*" ); 

    v3d iFrame (in my_awesome_app.js for example):

    window.onmessage =  function(event) {
        if(event.data.event_id === 'myMessage'){
            console.log(event.data.data);
        }
    };
    #31573

    Awesome! Thank you for sharing your solution! :good:

    Chief 3D Verger | LinkedIn | Twitter

    #63266
    solid
    Customer

    it turns out that the data can be transferred back?

    Webgl Interactive Development https://www.blend3dweb.ru/

    #63267
    kdv
    Participant

    the data can be transferred back

    What do you mean? Back to where?

    Puzzles and JS. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of meaning at all.

    #63268
    solid
    Customer

    passing window.postmessage to the parent page

    window.parent.postMessage('scene_loaded', "*");

    • This reply was modified 12 months ago by solid.

    Webgl Interactive Development https://www.blend3dweb.ru/

    #63270
    kdv
    Participant

    You may try. I suppose it’s quite possible.

    Puzzles and JS. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of meaning at all.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.