Package com.oorian.html.js
Class WindowApi
java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.WindowApi
Provides browser window management functionality from server-side Java code.
This class wraps browser window APIs, allowing server-side code to open new windows, close windows, trigger printing, and control page unload behavior.
All methods are provided in two forms:
- Convenience form - No page parameter; uses thread-local page lookup
- Efficient form - Accepts page parameter; avoids thread-local lookup
Usage:
// Open a URL in a new window
WindowApi.openNew("/report");
// Open with specific target
WindowApi.openNew("/report", "_blank");
// Print the current page
WindowApi.print();
// Block page unload (show confirmation dialog)
WindowApi.blockUnload();
// Efficient form when page reference is available
WindowApi.openNew(this, "/report");
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDisplays an alert dialog with the specified message.static voidDisplays an alert dialog with the specified message using the current page context.static voidBlocks the page from unloading by showing a confirmation dialog using the current page context.static voidblockUnload(HtmlPage page) Blocks the page from unloading by showing a confirmation dialog.static voidblur()Removes focus from the browser window using the current page context.static voidRemoves focus from the browser window.static voidCloses a browser window with the specified name.static voidCloses a browser window with the specified name using the current page context.static voidfocus()Brings the browser window to the front and gives it focus using the current page context.static voidBrings the browser window to the front and gives it focus.static voidOpens a URL in a new browser window.static voidOpens a URL in a new browser window with the specified target.static voidOpens a URL in a new browser window with the specified name and features.static voidOpens a URL in a new browser window using the current page context.static voidOpens a URL in a new browser window with the specified target using the current page context.static voidOpens a URL in a new browser window with the specified name and features using the current page context.static voidprint()Opens the browser's print dialog for the current page using the current page context.static voidOpens the browser's print dialog for the current page.static voidPrints the content from the specified URL.static voidPrints the content from the specified URL using the current page context.static voidPrints the content of the specified HtmlPage using the current page context.static voidPrints the content of the specified HtmlPage.static voidscrollBy(int deltaX, int deltaY) Scrolls the window by the specified amount using the current page context.static voidScrolls the window by the specified amount.static voidscrollTo(int x, int y) Scrolls the window to the specified coordinates using the current page context.static voidScrolls the window to the specified coordinates.static voidUnblocks the page from unloading using the current page context.static voidunblockUnload(HtmlPage page) Unblocks the page from unloading.
-
Constructor Details
-
WindowApi
public WindowApi()
-
-
Method Details
-
openNew
Opens a URL in a new browser window using the current page context.- Parameters:
url- The URL to open.
-
openNew
Opens a URL in a new browser window.- Parameters:
page- The page initiating the window open.url- The URL to open.
-
openNew
Opens a URL in a new browser window with the specified target using the current page context.- Parameters:
url- The URL to open.target- The target window name (e.g., "_blank", "_self", or a custom name).
-
openNew
Opens a URL in a new browser window with the specified target.- Parameters:
page- The page initiating the window open.url- The URL to open.target- The target window name (e.g., "_blank", "_self", or a custom name).
-
openNew
Opens a URL in a new browser window with the specified name and features using the current page context.- Parameters:
url- The URL to open.name- The window name.specs- The window features specification (e.g., "width=800,height=600").
-
openNew
Opens a URL in a new browser window with the specified name and features.- Parameters:
page- The page initiating the window open.url- The URL to open.name- The window name.specs- The window features specification (e.g., "width=800,height=600").
-
close
Closes a browser window with the specified name using the current page context.- Parameters:
windowName- The name of the window to close.
-
close
Closes a browser window with the specified name.- Parameters:
page- The page initiating the window close.windowName- The name of the window to close.
-
print
public static void print()Opens the browser's print dialog for the current page using the current page context. -
print
Opens the browser's print dialog for the current page.- Parameters:
page- The page to print.
-
print
Prints the content from the specified URL using the current page context.- Parameters:
url- The URL of the content to print.
-
print
Prints the content from the specified URL.- Parameters:
page- The page initiating the print.url- The URL of the content to print.
-
printPage
Prints the content of the specified HtmlPage using the current page context.- Parameters:
targetPage- The page to print.
-
printPage
Prints the content of the specified HtmlPage.- Parameters:
page- The page initiating the print.targetPage- The page to print.
-
blockUnload
public static void blockUnload()Blocks the page from unloading by showing a confirmation dialog using the current page context.When enabled, the browser will show a confirmation dialog when the user attempts to navigate away from or close the page.
-
blockUnload
Blocks the page from unloading by showing a confirmation dialog.When enabled, the browser will show a confirmation dialog when the user attempts to navigate away from or close the page.
- Parameters:
page- The page to block unloading for.
-
unblockUnload
public static void unblockUnload()Unblocks the page from unloading using the current page context.Removes the confirmation dialog that was previously enabled with
blockUnload(). -
unblockUnload
Unblocks the page from unloading.Removes the confirmation dialog that was previously enabled with
blockUnload(HtmlPage).- Parameters:
page- The page to unblock.
-
focus
public static void focus()Brings the browser window to the front and gives it focus using the current page context. -
focus
Brings the browser window to the front and gives it focus.- Parameters:
page- The page whose window to focus.
-
blur
public static void blur()Removes focus from the browser window using the current page context. -
blur
Removes focus from the browser window.- Parameters:
page- The page whose window to blur.
-
scrollTo
public static void scrollTo(int x, int y) Scrolls the window to the specified coordinates using the current page context.- Parameters:
x- The horizontal scroll position in pixels.y- The vertical scroll position in pixels.
-
scrollTo
Scrolls the window to the specified coordinates.- Parameters:
page- The page whose window to scroll.x- The horizontal scroll position in pixels.y- The vertical scroll position in pixels.
-
scrollBy
public static void scrollBy(int deltaX, int deltaY) Scrolls the window by the specified amount using the current page context.- Parameters:
deltaX- The horizontal scroll amount in pixels (positive = right, negative = left).deltaY- The vertical scroll amount in pixels (positive = down, negative = up).
-
scrollBy
Scrolls the window by the specified amount.- Parameters:
page- The page whose window to scroll.deltaX- The horizontal scroll amount in pixels (positive = right, negative = left).deltaY- The vertical scroll amount in pixels (positive = down, negative = up).
-
alert
Displays an alert dialog with the specified message using the current page context.- Parameters:
message- The message to display in the alert dialog.
-
alert
Displays an alert dialog with the specified message.- Parameters:
page- The page to display the alert on.message- The message to display in the alert dialog.
-