title: Hooking a GWT event onto an element in an external iframe
body: <p>I am writing a GWT app that involves interacting with an external document in an iframe. As a proof of concept, I am trying to attach a click handler to a button.</p>
  
  <p>The following works in javascript</p>
  
  <pre><code>var iframe = document.getElementById("rawJSIFrame");
  var doc = iframe.contentDocument;
  var body = doc.body;
  var button = doc.getElementsByTagName("input").namedItem("submit");
  button.onclick = function() {
      alert("Clicked!");
  };
  </code></pre>
  
  <p>Trying to do the equivalent in GWT, I did the following:</p>
  
  <pre><code>public void addClickHandlerToSubmitButton(String buttonElementName, ClickHandler clickHandler) {
      IFrameElement iframe = IFrameElement.as(frame.getElement());
      Document frameDocument = getIFrameDocument(iframe);
      if (frameDocument != null) {
          Element buttonElement = finder(frameDocument).tag("input").name(buttonElementName).findOne();
          ElementWrapper wrapper = new ElementWrapper(buttonElement);
          HandlerRegistration handlerRegistration = wrapper.addClickHandler(clickHandler);
      }
  }
  
  private native Document getIFrameDocument(IFrameElement iframe)/*-{
          return iframe.contentDocument;
  }-*/;
  </code></pre>
  
  <p>The following is the ElementWrapper class:</p>
  
  <pre><code>public class ElementWrapper extends Widget implements HasClickHandlers {
  
      public ElementWrapper(Element theElement) {
          setElement(theElement);
      }
  
      public HandlerRegistration addClickHandler(ClickHandler handler) {
          return addDomHandler(handler, ClickEvent.getType());
      }
  
  
  }
  </code></pre>
  
  <p>The code to find the button works fine but the actual click event handler is not getting invoked. Has anybody had a similar issue before, and how did you resolve it?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Tin</p>