Hi I’m trying to display html content from external file located on my hard drive with WebView. There is also reference to js file inside the html. When I run my program the output window is empty. I’am using Intellij IDEA. My source files look like this:
js file src.js:
function foo()
{
document.getElementById("t1").innerText="test"
}
html file h.html:
<!DOCTYPE html>
<html>
<script type="text/javascript" src="C:bosrc.js"></script>
<body>
<h1>My First Heading</h1>
<button onClick="foo()">
<div id="t1">click me</div>
</button>
</body>
</html>
This is my Java source code:
@FXML
private WebView webView;
public void initialize(URL location, ResourceBundle resources) {
webView.getEngine().load("C:/bo/h.html");
loadPage();
}
I expect when I run my application to see the web page in the output window. I also expect when I click on button the text to change from “click me” to “test”. What I’am doing wrong ? The main idea is to diaplay html content linked to external js file. When I put the html content as an argument I can see the web page in the output window but the button won’t change the text because the js file is not accessible. Does the WebView provide the best way to display HTML content in javafx application that run on Windows PC. If it’s not, suggest a better way to display web content please.
6