views:

708

answers:

3

Using GWT 1.6.4, I have the following code to retrieve the dimensions of the browser window:

RootPanel panel = RootPanel.get();

int height = panel.getOffsetHeight();
int width = panel.getOffsetWidth();

Now, in the Hosted Mode browser, and in IE (but I believe the hosted mode browser uses IE, right?), this returns the correct values for both width and height. However, in FF3, width gives the correct value, but height is always zero. Can anyone explain this? Am I doing something wrong? What is the correct way to retrieve the height of the window in Firefox, and is there one method that works correctly in both IE and Firefox?

A: 

Using javascript, you can grab the window height with:

int height = document.body.clientHeight;

Now whether GWT gives you anyway to specify specific javascript pieces, I don't know. You may want to post in the GWT google group, which can be found at: http://groups.google.com/group/Google-Web-Toolkit?pli=1

Joe Bubna
+1  A: 

Did you try the Window.getClientHeight() and Window.getClientWidth() methods?

Check out the JavaDocs.

jgindin
A: 

I'm taking a wild guess here: in Firefox, in the moment you check RootPanel.get().getOffsetHeight(), it's empty and not stretching into the viewport, only horizontally. So better use Window.getClientHeight() if you need the actual window/viewport dimensions.