Class WindowApi


public class WindowApi extends JavaScriptApi
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    alert(HtmlPage page, String message)
    Displays an alert dialog with the specified message.
    static void
    alert(String message)
    Displays an alert dialog with the specified message using the current page context.
    static void
    Blocks the page from unloading by showing a confirmation dialog using the current page context.
    static void
    Blocks the page from unloading by showing a confirmation dialog.
    static void
    Removes focus from the browser window using the current page context.
    static void
    blur(HtmlPage page)
    Removes focus from the browser window.
    static void
    close(HtmlPage page, String windowName)
    Closes a browser window with the specified name.
    static void
    close(String windowName)
    Closes a browser window with the specified name using the current page context.
    static void
    Brings the browser window to the front and gives it focus using the current page context.
    static void
    Brings the browser window to the front and gives it focus.
    static void
    openNew(HtmlPage page, String url)
    Opens a URL in a new browser window.
    static void
    openNew(HtmlPage page, String url, String target)
    Opens a URL in a new browser window with the specified target.
    static void
    openNew(HtmlPage page, String url, String name, String specs)
    Opens a URL in a new browser window with the specified name and features.
    static void
    Opens a URL in a new browser window using the current page context.
    static void
    openNew(String url, String target)
    Opens a URL in a new browser window with the specified target using the current page context.
    static void
    openNew(String url, String name, String specs)
    Opens a URL in a new browser window with the specified name and features using the current page context.
    static void
    Opens the browser's print dialog for the current page using the current page context.
    static void
    Opens the browser's print dialog for the current page.
    static void
    print(HtmlPage page, URL url)
    Prints the content from the specified URL.
    static void
    print(URL url)
    Prints the content from the specified URL using the current page context.
    static void
    printPage(HtmlPage targetPage)
    Prints the content of the specified HtmlPage using the current page context.
    static void
    printPage(HtmlPage page, HtmlPage targetPage)
    Prints the content of the specified HtmlPage.
    static void
    scrollBy(int deltaX, int deltaY)
    Scrolls the window by the specified amount using the current page context.
    static void
    scrollBy(HtmlPage page, int deltaX, int deltaY)
    Scrolls the window by the specified amount.
    static void
    scrollTo(int x, int y)
    Scrolls the window to the specified coordinates using the current page context.
    static void
    scrollTo(HtmlPage page, int x, int y)
    Scrolls the window to the specified coordinates.
    static void
    Unblocks the page from unloading using the current page context.
    static void
    Unblocks the page from unloading.

    Methods inherited from class com.oorian.html.js.JavaScriptApi

    executeJs, executeJs, executeJs, executeJs, getPage

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WindowApi

      public WindowApi()
  • Method Details

    • openNew

      public static void openNew(String url)
      Opens a URL in a new browser window using the current page context.
      Parameters:
      url - The URL to open.
    • openNew

      public static void openNew(HtmlPage page, String url)
      Opens a URL in a new browser window.
      Parameters:
      page - The page initiating the window open.
      url - The URL to open.
    • openNew

      public static void openNew(String url, String target)
      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

      public static void openNew(HtmlPage page, String url, String target)
      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

      public static void openNew(String url, String name, String specs)
      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

      public static void openNew(HtmlPage page, String url, String name, String specs)
      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

      public static void close(String windowName)
      Closes a browser window with the specified name using the current page context.
      Parameters:
      windowName - The name of the window to close.
    • close

      public static void close(HtmlPage page, String windowName)
      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

      public static void print(HtmlPage page)
      Opens the browser's print dialog for the current page.
      Parameters:
      page - The page to print.
    • print

      public static void print(URL url)
      Prints the content from the specified URL using the current page context.
      Parameters:
      url - The URL of the content to print.
    • print

      public static void print(HtmlPage page, URL url)
      Prints the content from the specified URL.
      Parameters:
      page - The page initiating the print.
      url - The URL of the content to print.
    • printPage

      public static void printPage(HtmlPage targetPage)
      Prints the content of the specified HtmlPage using the current page context.
      Parameters:
      targetPage - The page to print.
    • printPage

      public static void printPage(HtmlPage page, HtmlPage targetPage)
      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

      public static void blockUnload(HtmlPage page)
      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

      public static void unblockUnload(HtmlPage page)
      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

      public static void focus(HtmlPage page)
      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

      public static void blur(HtmlPage page)
      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

      public static void scrollTo(HtmlPage page, int x, int y)
      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

      public static void scrollBy(HtmlPage page, int deltaX, int deltaY)
      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

      public static void alert(String message)
      Displays an alert dialog with the specified message using the current page context.
      Parameters:
      message - The message to display in the alert dialog.
    • alert

      public static void alert(HtmlPage page, String message)
      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.