Package com.oorian.html.js.visibility
Class VisibilityApi
java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.visibility.VisibilityApi
Provides access to the browser's Page Visibility API from server-side Java code.
This class wraps the browser's Page Visibility API, enabling server-side code to be notified when the page becomes visible or hidden (e.g., when the user switches tabs).
Usage:
public class DashboardPage extends HtmlPage implements VisibilityListener {
@Override
protected void createBody(Body body) {
body.registerListener(this, VisibilityChangeEvent.class);
VisibilityApi.startListening(body);
}
@Override
public void onEvent(VisibilityChangeEvent event) {
if (event.isVisible()) {
// Resume updates
} else {
// Pause updates to save resources
}
}
}
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstartListening(Element element) Starts listening for visibility changes using the current page context.static voidstartListening(HtmlPage page, Element element) Starts listening for visibility changes.static voidStops listening for visibility changes using the current page context.static voidstopListening(HtmlPage page) Stops listening for visibility changes.
-
Constructor Details
-
VisibilityApi
public VisibilityApi()
-
-
Method Details
-
startListening
Starts listening for visibility changes using the current page context.- Parameters:
element- The element that will receive visibility events.
-
startListening
Starts listening for visibility changes.- Parameters:
page- The page context.element- The element that will receive visibility events.
-
stopListening
public static void stopListening()Stops listening for visibility changes using the current page context. -
stopListening
Stops listening for visibility changes.- Parameters:
page- The page context.
-