在WebEngine
状态表的JavaScript的用户界面的方法和属性与其对应的WebEngine回调。
其中window.close()
对应于WebEngine
的onVisibilityChanged
回调。
一个快速的方法来尝试,在这种情况下,可能是:
webEngine.getOnVisibilityChanged().handle(closeWindowEvent); //event definition below
接着是
webEngine.executeScript("window.close()");
中,你要确保窗口的另一种方法是关闭的是定义一个事件,可以通过WebView's EventDispatcher
当前节点。
// 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
在试图取消只是加载网页时,您可以使用executeScript
做:
webEngine.executeScript("window.stop()");
我没有试图关闭一个窗口,只是取消加载的网页。 – Pablo
@Pablo'window.stop()'在这种情况下可以帮助你...? – nullpointer