Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you cancel a webview loading a web site?

What I'm trying to implement is essentially the cancel button of a browser but using JavaFX's webview. This is the code I have so far:

Worker<Void> loadWorker = webView.getEngine().getLoadWorker();
if (loadWorker != null) {
    Platform.runLater(() -> loadWorker.cancel());
}

but it sometimes work and sometimes doesn't.

What's the proper way of canceling the webview/webengine task of loading a page?

like image 315
pupeno Avatar asked Sep 27 '17 17:09

pupeno


1 Answers

After canceling the webEngine task, can you try with setting the content of the webEngine to null :

webView.getEngine().load(null);
like image 193
Priyanka Avatar answered Oct 06 '22 12:10

Priyanka