Is there something like jquerys ready()
in GWT. I add an iframe and will check when the DOM is ready.
Asked
Active
Viewed 4,232 times
3

Andreas Köberle
- 106,652
- 57
- 273
- 297
3 Answers
4
document.ready()
is similar to the onModuleLoad()
method in your GWT EntryPoint. They both execute, when the document is ready.

Chris Lercher
- 37,264
- 20
- 99
- 131
-
but i dont want to start a new app, I jsut want to see if the dom of the iframe is ready. – Andreas Köberle Aug 31 '11 at 11:54
-
Well, I assumed, that your GWT code is in the iframe (so its onModuleLoad method will be called, when it's ready). I'm not sure, if the thing you want to do (waiting until the iframe is ready) is possible at all, as long as you can't run javascript from within the iframe. At least, I'm pretty sure, that this will not work reliably (also not with jQuery). There was a similar situation in [this answer](http://stackoverflow.com/questions/5042139/gwt-easiest-way-to-do-a-simple-loading-screen-until-file-is-loaded/5044660#5044660), and it looks as if this doesn't work with Chrome. – Chris Lercher Aug 31 '11 at 12:03
-
It should be no problem in JavaScript. I can get the window object of the iframe and add an event to it. See http://stackoverflow.com/questions/205087/jquery-ready-in-a-dynamically-inserted-iframe/205221#205221 – Andreas Köberle Aug 31 '11 at 12:31
-
You should really test this with Chrome. When I tried adding an `onload` attribute to an iframe, chrome (as opposed to all other browsers) always fired the event immediately, long before the entire content was loaded. (I made the server send the content very slowly, so this was clearly visible.) – Chris Lercher Aug 31 '11 at 13:12
-
its not about the onload event its about domcontentloaded I'm looking for – Andreas Köberle Aug 31 '11 at 15:14
4
You can create a deferred command to execute when the browser event loop returns.
boolean ready=false;
public void onModuleLoad() {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
ready=true;
Window.alert(ready+"");
}
});
for (int i=0;i<9999;i++){
RootPanel.get().add(new Label(ready+""));
}
}
This example places 9999 labels at DOM, only after then alerts true

pistolPanties
- 1,880
- 13
- 18
-
Can you explain how this could help me find out if the domready is fired in an iframe? – Andreas Köberle Sep 02 '11 at 08:42
-
I did not think the question was specifically about capturing domready event. Regarding your comment, I think you could use [javascript](http://www.javascriptkit.com/dhtmltutors/domready.shtml) to capture the event and [JSNI](http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#calling) to call a GWT method when the event fires – pistolPanties Sep 02 '11 at 10:55
-
Sure I can do this JSNI, but the question was about a buildin solution in GWT. – Andreas Köberle Sep 02 '11 at 13:21
0
Not really: it isn't a paradigm that really translates well to Java. You might want to just include jQuery or Zepto and use the ready
function from one of those.

Femi
- 64,273
- 8
- 118
- 148