1
0
-1

Hello,

I was wondering with the iframe comp if one can do these two things.

On page load call a groovy service and push that data to a data field that the object in the iframe can access?

Can I then pass data back into the groovy service from the object in the iframe?

I don't have any code samples but was wondering if this is possible how does one do it.

Thanks

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi Jorge,

      Technically, you can do this, but I'd suggest looking for alternate ways to achieve your objective as there are several issues such as timing, security and cross-browser support you might encounter to frustrate you.

      You also need to be able to control the content of the iframe window, so you can implement some JavaScript code in it.

      The parent document and the iframe have different DOM structures, so you can't 'share' objects between the structures if they are from different domains.  You can, however, use window.postMessage to post messages from one window to another.

      In your main window, you can post a message to an iframe with code such as this fragment where I post a message to a different Maestro form in an iframe:

          document.querySelector('iframe').contentWindow.postMessage('Hello', 'http://localhost:9080/web-plugin/servlet/SmartForm.html?formCode=iframereceiver')

      In the iframe, you must be able to execute JavaScript code to receive the message, with something like this:

          if (window.addEventListener) {
              window.addEventListener("message", receiveMessage, false);
          } else {
              window.attachEvent("onmessage", displayMessage);
          }

          function receiveMessage(event)
          {
              console.log(event);
          }

      That would give you one-way message passing.  You would use similar code on both ends to implement passing messages back the other way, probably by calling event.source.postMessage in the iframe.


        CommentAdd your comment...