Search code examples
gwtiframerefreshframereload

Reloading an iframe in GWT


I am currently working on a GWT project where I am displaying an HTML file within an iframe in my application. This HTML file is actually being written to as it is getting displayed, and I am hoping to be able to reload the frame so that the changes made to the HTML file are reflected on screen. I am able to do this two different ways that both work when running in development mode, however neither seem to work when the project is deployed.

The first method I tried was setting the frame's URL to itself:

frame.setUrl(frame.getUrl());

The second method I tried using JSNI:

public native void refresh() /*-{
  if($doc.getElementById('__reportFrame') != null) {
    $doc.getElementById('__reportFrame').src =
       $doc.getElementById('__reportFrame').src;
  }
}-*/;

When deployed, the frame gets displayed in a Window, and when the file is finished being written to, a call to either of these refresh methods is made, and the frame refreshes to contain the finished HTML file. When I am deployed, the call to refresh does not reload the contents of the frame, however if I bring up the frame's context menu (in Firefox), then go into 'This Frame', and click Reload, it successfully reloads the frame to contain the finished HTML file. I have tested this on multiple versions of Firefox without any luck.

Does anyone have any suggestions? Why would the behavior be different from one mode to the other?

Thanks.


Solution

  • wow, google is really fast with his search^^

    You can use some JSNI to do this. Create a method such as

    protected native void reloadIFrame(Element iframeEl) /-{ iframeEl.contentWindow.location.reload(true); }-/;

     Then call it with your iFrame element
    

    so your question you posted twice was already answerd here http://groups.google.com/group/google-web-toolkit/browse_thread/thread/64aa7712890652d3