public class

Window

extends Object
java.lang.Object
   ↳ com.google.gwt.user.client.Window

Class Overview

This class provides access to the browser window's methods, properties, and events.

Summary

Nested Classes
class Window.ClosingEvent Fired just before the browser window closes or navigates to a different site. 
interface Window.ClosingHandler Handler for Window.ClosingEvent events. 
class Window.Location This class provides access to the browser's location's object. 
class Window.Navigator This class provides access to the browser's navigator object. 
class Window.ScrollEvent Fired when the browser window is scrolled. 
interface Window.ScrollHandler Handler for Window.ScrollEvent events. 
Public Methods
static HandlerRegistration addCloseHandler(CloseHandler<Window> handler)
Adds a CloseEvent handler.
static HandlerRegistration addResizeHandler(ResizeHandler handler)
Adds a ResizeEvent handler.
static void addWindowCloseListener(WindowCloseListener listener)
static HandlerRegistration addWindowClosingHandler(Window.ClosingHandler handler)
Adds a Window.ClosingEvent handler.
static void addWindowResizeListener(WindowResizeListener listener)
This method is deprecated. use addResizeHandler(ResizeHandler) instead
static HandlerRegistration addWindowScrollHandler(Window.ScrollHandler handler)
Adds a Window.ScrollEvent handler.
static void addWindowScrollListener(WindowScrollListener listener)
This method is deprecated. use addWindowScrollHandler(ScrollHandler) instead
static void alert(String msg)
Displays a message in a modal dialog box.
static boolean confirm(String msg)
Displays a message in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.
static void enableScrolling(boolean enable)
Use this method to explicitly disable the window's scrollbars.
static int getClientHeight()
Gets the height of the browser window's client area excluding the scroll bar.
static int getClientWidth()
Gets the width of the browser window's client area excluding the vertical scroll bar.
static int getScrollLeft()
Gets the window's scroll left.
static int getScrollTop()
Get the window's scroll top.
static String getTitle()
Gets the browser window's current title.
static void moveBy(int dx, int dy)
Moves a window's left and top edge to a specified number of pixels relative to its current coordinates.
static void moveTo(int x, int y)
Moves a window's left and top edge to the specified coordinates.
static void open(String url, String name, String features)
Opens a new browser window.
static void print()
Prints the document in the window, as if the user had issued a "Print" command.
static String prompt(String msg, String initialValue)
Displays a request for information in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.
static void removeWindowCloseListener(WindowCloseListener listener)
Removes a window closing listener.
static void removeWindowResizeListener(WindowResizeListener listener)
Removes a window resize listener.
static void removeWindowScrollListener(WindowScrollListener listener)
Removes a window scroll listener.
static void resizeBy(int width, int height)
Resizes the window by the specified width and height.
static void resizeTo(int width, int height)
Resizes the window to the specified width and height.
static void scrollTo(int left, int top)
Scroll the window to the specified position.
static void setMargin(String size)
Sets the size of the margins used within the window's client area.
static void setStatus(String status)
Sets the status text for the window, if permitted by the browser's settings.
static void setTitle(String title)
Sets the browser window's title.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static HandlerRegistration addCloseHandler (CloseHandler<Window> handler)

Adds a CloseEvent handler.

Parameters
handler the handler
Returns
  • returns the handler registration

public static HandlerRegistration addResizeHandler (ResizeHandler handler)

Adds a ResizeEvent handler.

Parameters
handler the handler
Returns
  • returns the handler registration

public static void addWindowCloseListener (WindowCloseListener listener)

This method is deprecated.
use addWindowClosingHandler(ClosingHandler) and addCloseHandler(CloseHandler) instead

Adds a listener to receive window closing events.

Parameters
listener the listener to be informed when the window is closing

public static HandlerRegistration addWindowClosingHandler (Window.ClosingHandler handler)

Adds a Window.ClosingEvent handler.

Parameters
handler the handler
Returns
  • returns the handler registration

public static void addWindowResizeListener (WindowResizeListener listener)

This method is deprecated.
use addResizeHandler(ResizeHandler) instead

Adds a listener to receive window resize events.

Parameters
listener the listener to be informed when the window is resized

public static HandlerRegistration addWindowScrollHandler (Window.ScrollHandler handler)

Adds a Window.ScrollEvent handler.

Parameters
handler the handler
Returns
  • returns the handler registration

public static void addWindowScrollListener (WindowScrollListener listener)

This method is deprecated.
use addWindowScrollHandler(ScrollHandler) instead

Adds a listener to receive window scroll events.

Parameters
listener the listener to be informed when the window is scrolled

public static void alert (String msg)

Displays a message in a modal dialog box.

Parameters
msg the message to be displayed.

public static boolean confirm (String msg)

Displays a message in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.

Parameters
msg the message to be displayed.
Returns
  • true if 'OK' is clicked, false if 'Cancel' is clicked.

public static void enableScrolling (boolean enable)

Use this method to explicitly disable the window's scrollbars. Applications that choose to resize their user-interfaces to fit within the window's client area will normally want to disable window scrolling.

Parameters
enable false to disable window scrolling

public static int getClientHeight ()

Gets the height of the browser window's client area excluding the scroll bar.

Returns
  • the window's client height

public static int getClientWidth ()

Gets the width of the browser window's client area excluding the vertical scroll bar.

Returns
  • the window's client width

public static int getScrollLeft ()

Gets the window's scroll left.

Returns
  • window's scroll left

public static int getScrollTop ()

Get the window's scroll top.

Returns
  • the window's scroll top

public static String getTitle ()

Gets the browser window's current title.

Returns
  • the window's title.

public static void moveBy (int dx, int dy)

Moves a window's left and top edge to a specified number of pixels relative to its current coordinates.

NOTE: In Chrome, this method only works with windows created by Window.open().

Parameters
dx A positive or a negative number that specifies how many pixels to move the left edge by
dy A positive or a negative number that specifies how many pixels to move the top edge by

public static void moveTo (int x, int y)

Moves a window's left and top edge to the specified coordinates.

NOTE: In Chrome, this method only works with windows created by Window.open().

Parameters
x The left coordinate
y The top coordinate

public static void open (String url, String name, String features)

Opens a new browser window. The "name" and "features" arguments are specified here.

Parameters
url the URL that the new window will display
name the name of the window (e.g. "_blank")
features the features to be enabled/disabled on this window

public static void print ()

Prints the document in the window, as if the user had issued a "Print" command.

public static String prompt (String msg, String initialValue)

Displays a request for information in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.

Parameters
msg the message to be displayed
initialValue the initial value in the dialog's text field
Returns
  • the value entered by the user if 'OK' was pressed, or null if 'Cancel' was pressed

public static void removeWindowCloseListener (WindowCloseListener listener)

Removes a window closing listener.

Parameters
listener the listener to be removed

public static void removeWindowResizeListener (WindowResizeListener listener)

Removes a window resize listener.

Parameters
listener the listener to be removed

public static void removeWindowScrollListener (WindowScrollListener listener)

Removes a window scroll listener.

Parameters
listener the listener to be removed

public static void resizeBy (int width, int height)

Resizes the window by the specified width and height. This method moves the bottom right corner of the window by the specified number of pixels defined. The top left corner will not be moved (it stays in its original coordinates).

NOTE: In Chrome, this method only works with windows created by Window.open().

Parameters
width A positive or a negative number that specifies how many pixels to resize the width by
height A positive or a negative number that specifies how many pixels to resize the height by

public static void resizeTo (int width, int height)

Resizes the window to the specified width and height.

NOTE: In Chrome, this method only works with windows created by Window.open().

Parameters
width The width of the window, in pixels
height The height of the window, in pixels

public static void scrollTo (int left, int top)

Scroll the window to the specified position.

Parameters
left the left scroll position
top the top scroll position

public static void setMargin (String size)

Sets the size of the margins used within the window's client area. It is sometimes necessary to do this because some browsers, such as Internet Explorer, add margins by default, which can confound attempts to resize panels to fit exactly within the window.

Parameters
size the window's new margin size, in CSS units.

public static void setStatus (String status)

Sets the status text for the window, if permitted by the browser's settings.

Parameters
status the new message to display.

public static void setTitle (String title)

Sets the browser window's title.

Parameters
title the new window title.