The table in the WebEngine
states the JavaScript user interface methods and properties with their corresponding WebEngine callbacks.
Where window.close()
corresponds to the onVisibilityChanged
callback of the WebEngine
.
A quick way to try out, in that case, could be :
webEngine.getOnVisibilityChanged().handle(closeWindowEvent); //event definition below
followed by a
webEngine.executeScript("window.close()");
Another way in which you make sure the window is closed is to define an event which could be dispatched by the WebView's EventDispatcher
for the current node.
// Here the event to be dispatched for closing the window shall be
WebEvent<Boolean> closeWindowEvent = new WebEvent<>(webEngine, VISIBILITY_CHANGED, Boolean.FALSE);
webView.getEventDispatcher().dispatchEvent(closeWindowEvent, null); // no further events
In case of trying to cancel loading the web page only, you can make use of the executeScript
to do:
webEngine.executeScript("window.stop()");