I am trying to call a JavaScript function from a JavaFX WebView on a JavaFX button click event.
I am using the following code, but it is not working:
try {
File file = new File("F:\inputfile\hello.htm");
WebEngine webengine = webview.getEngine();
webengine.load(file.toURI().toURL().toString());
} catch(Exception ex) {
ex.printStackTrace();
}
On any button click I want to execute the test()
JavaScript method in the html file:
webengine.executeScript("test()");
And the JavaScript method in html file is:
<script language="javascript">
function test()
{
window.scrollBy(0, 20);
}
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…