6
我想在JavaFX按鈕點擊事件上從JavaFX WebView調用JavaScript函數。如何在Button上單擊調用JavaFX WebView中的JavaScript函數?
我使用下面的代碼,但它不工作:
try {
File file = new File("F:\\inputfile\\hello.htm");
WebEngine webengine = webview.getEngine();
webengine.load(file.toURI().toURL().toString());
} catch(Exception ex) {
ex.printStackTrace();
}
上的任何按鈕點擊我要在HTML文件來執行test()
JavaScript方法:
webengine.executeScript("test()");
而在HTML文件中的JavaScript方法是:
<script language="javascript">
function test()
{
window.scrollBy(0, 20);
}
</script>