I have a GWT application that features two frames (com.google.gwt.user.client.ui.Frame). Via Frame.setUrl(…) I can load arbitrary web pages without any problems. Of course, user then can click on links on the loaded pages, which in turn load the corresponding pages? How can I keep track of the currently loaded pages in both frames?
Below are my current attempt using two types of listeners; I found the code snippets on the Web. Both events fire, but still I don’t know how to get the current loaded URL
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.EventListener;
import com.google.gwt.user.client.ui.Frame;
public class BrowserTabFrame extends Frame implements EventListener {
public BrowserTabFrame() {
super();
sinkEvents(Event.ONLOAD);
addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
System.out.println(event.getSource());
// <iframe style="visibility: visible;" id="ext-gen17" src="http://..." class="gwt-Frame"></iframe>
// however, the src attribute never changes
}
});
}
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
if (DOM.eventGetType(event) == Event.ONLOAD)
System.out.println(event.getCurrentEventTarget());
// [object HTMLIFrameElement]
// no idea what to do with it
}
}
Thanks for any hints!
Christian
The
srcattribute of aniframewill never change but theURLproperty of the containeddocumentwill. You can get this value using JSNI:However note that, if the security context (any of protocol, domain or port number) of the
iframechanges, the browser will not allow the containing application to access thedocumentin the frame.