webView:
是一个管理webEngine和显示它中间内容的节点。这个对象只能从fx的线程中创建。
webEngine:
是一个管理网页的不可见控件,它可以加载网页,创建文档模型,运行javascript,加载必要的样式,很重要的是它提供的网页的文档模型很不错,另外,它还可以实现java应用程序和javascript的双向通信。
1.访问页面
1.通过任意的url地址进行访问,基于java.net包来实现,engine.load(String url)即可
2.从in-memory String的方式(内存查找已有网址的字符串) 通过loadContent(java.lang.String)或者loadContent(java.lang.String, java.lang.String)的方式实现。
loadContent(java.lang.String URLcontext):直接加载给定的url内容,当你在内存中有一个要访问的url地址时非常快,或者你要加载一些url无法表示的数据时,用这个。
loadContent(java.lang.String URLcontext, java.lang.String contentType):和上面的相比,你可以指定要加载的类型,所以可以加载html以外的类型。
2.回调函数
这些回调函数被调用时,使用页面上的脚本运行请求对用户界面进行操作,例如,打开一个弹出窗口,或改变状态的文本。一个webengine对象不能处理这些请求内部,所以它将请求传递给相应的回调。如果没有回调是一个具体的操作定义,该请求被忽略。
The table below shows JavaScript user interface methods and properties with their corresponding WebEngine callbacks:
| JavaScript method/property | WebEngine callback |
|---|---|
window.alert() | onAlert |
window.confirm() | confirmHandler |
window.open() | createPopupHandler |
window.open() andwindow.close() | onVisibilityChanged |
window.prompt() | promptHandler |
Setting window.status | onStatusChanged |
Setting any of the following:window.innerWidth, window.innerHeight,window.outerWidth, window.outerHeight,window.screenX, window.screenY,window.screenLeft, window.screenTop | onResized |
事例代码:
Stage stage;
webEngine.setOnResized(
new EventHandler<WebEvent<Rectangle2D>>() {
public void handle(WebEvent<Rectangle2D> ev) {
Rectangle2D r = ev.getData();
stage.setWidth(r.getWidth());
stage.setHeight(r.getHeight());
}
});也就是说,webEngine可以获得javascript的内容,以及用户的响应,实现了java程序和javascript的交互。
3.文档对象入口
也就是支持dom解析
EventListener listener = new EventListener() {
public void handleEvent(Event ev) {
Platform.exit();
}
};
Document doc = webEngine.getDocument();
Element el = doc.getElementById("exit-app");
((EventTarget) el).addEventListener("click", listener, false);4.执行javascript
webEngine.executeScript("history.back()");5.就是java和javascript的交互,可以参考api
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
webView:
</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"></span>是一个管理webEngine和显示它中间内容的节点。这个对象只能从fx的线程中创建。
</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
webEngine:
</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"></span>是一个管理网页的不可见控件,它可以加载网页,创建文档模型,运行javascript,加载必要的样式,很重要的是它提供的网页的文档模型很不错,另外,它还可以实现java应用程序和javascript的双向通信。
</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; font-family: SimSun; font-size: 18px;"><span style="box-sizing: border-box; outline: 0px; font-weight: 700; word-break: break-all;">1.访问页面</span></span>
</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"></span>1.通过任意的url地址进行访问,基于java.net包来实现,engine.load(String url)即可
</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"></span>2.从in-memory String的方式(内存查找已有网址的字符串) 通过<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;"><a target="_blank" style="box-sizing: border-box; outline: 0px; color: rgb(78, 161, 219); cursor: pointer; word-break: break-all;">loadContent(java.lang.String)</a>或者</code><code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;"><a target="_blank" style="box-sizing: border-box; outline: 0px; color: rgb(78, 161, 219); cursor: pointer; word-break: break-all;">loadContent(java.lang.String, java.lang.String)</a>的方式实现。</code>
</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: "PingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; white-space: normal; ">
<br/>
</p>
<ul class="blockList list-paddingleft-2" style="list-style-type: none;">
<li>
<p>
<a target="_blank" style="box-sizing: border-box; outline: 0px; color: rgb(78, 161, 219); cursor: pointer; word-break: break-all; font-family: monospace;">loadContent(java.lang.String URLcontext)</a>:直接加载给定的url内容,当你在内存中有一个要访问的url地址时非常快,或者你要加载一些url无法表示的数据时,用这个。
</p>
</li>
<li>
<p>
<a target="_blank" style="box-sizing: border-box; outline: 0px; color: rgb(78, 161, 219); cursor: pointer; word-break: break-all; font-family: monospace;">loadContent(java.lang.String URLcontext, java.lang.String</a> <span style="box-sizing: border-box; outline: 0px; word-break: break-all; color: rgb(0, 0, 153);">contentType</span>):和上面的相比,你可以指定要加载的类型,所以可以加载html以外的类型。
</p>
</li>
</ul>
<p>
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; font-size: 18px;">2.回调函数</span>
</p>
<p>
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"><span style="box-sizing: border-box; outline: 0px; word-break: break-all; font-size: 12px;"><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">这些回调函数被调用时,使用页面上的脚本运行请求对用户界面进行操作,例如,打开一个弹出窗口,或改变状态的文本。</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">一个webengine对象不能处理这些请求内部,所以它将请求传递给相应的回调。</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">如果没有</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">回调</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">是一个</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">具体的操作</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">定义</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">,</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">该请求</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">被忽略</span><span style="box-sizing: border-box; outline: 0px; word-break: break-all; border: 1px solid transparent; font-family: arial; line-height: 22px;">。</span></span></span>
</p>
<p>
</p>
<ul class="blockList list-paddingleft-2" style="list-style-type: none;">
<li>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;">
The table below shows JavaScript user interface methods and properties with their corresponding <code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">WebEngine</code> callbacks:
</p>
<table width="820" style="width: 798px;">
<tbody style="box-sizing: border-box; outline: 0px; border: 0px; word-break: break-all;">
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); word-break: break-all;" class="firstRow">
<th style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; text-align: left; word-break: break-all; border-top-color: rgb(221, 221, 221); color: rgb(79, 79, 79); line-height: 22px; background-color: rgb(239, 243, 245);">
JavaScript method/property
</th>
<th style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; text-align: left; word-break: break-all; border-top-color: rgb(221, 221, 221); color: rgb(79, 79, 79); line-height: 22px; background-color: rgb(239, 243, 245);">
WebEngine callback
</th>
</tr>
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); background-color: rgb(247, 247, 247); word-break: break-all;">
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.alert()</code>
</td>
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">onAlert</code>
</td>
</tr>
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); word-break: break-all;">
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.confirm()</code>
</td>
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">confirmHandler</code>
</td>
</tr>
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); background-color: rgb(247, 247, 247); word-break: break-all;">
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.open()</code>
</td>
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">createPopupHandler</code>
</td>
</tr>
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); word-break: break-all;">
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.open()</code> and<br style="box-sizing: border-box; outline: 0px; word-break: break-all;"/><code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.close()</code>
</td>
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">onVisibilityChanged</code>
</td>
</tr>
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); background-color: rgb(247, 247, 247); word-break: break-all;">
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.prompt()</code>
</td>
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">promptHandler</code>
</td>
</tr>
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); word-break: break-all;">
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
Setting <code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.status</code>
</td>
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">onStatusChanged</code>
</td>
</tr>
<tr style="box-sizing: border-box; outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); background-color: rgb(247, 247, 247); word-break: break-all;">
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
Setting any of the following:<br style="box-sizing: border-box; outline: 0px; word-break: break-all;"/><code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.innerWidth</code>, <code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.innerHeight</code>,<br style="box-sizing: border-box; outline: 0px; word-break: break-all;"/><code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.outerWidth</code>, <code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.outerHeight</code>,<br style="box-sizing: border-box; outline: 0px; word-break: break-all;"/><code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.screenX</code>, <code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.screenY</code>,<br style="box-sizing: border-box; outline: 0px; word-break: break-all;"/><code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.screenLeft</code>, <code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">window.screenTop</code>
</td>
<td style="box-sizing: border-box; outline: 0px; padding: 8px; margin: 0px; word-break: break-all; color: rgb(79, 79, 79); line-height: 22px;">
<code style="box-sizing: border-box; outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; word-break: break-all;">onResized</code>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p>
事例代码:
</p>
<ul class="blockList list-paddingleft-2" style="list-style-type: none;">
<li>
<pre style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 24px; background-color: rgb(240, 240, 240); overflow-x: auto; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(0, 0, 0); word-break: break-all;">Stage stage;
webEngine.setOnResized(
new EventHandler<WebEvent<Rectangle2D>>() {
public void handle(WebEvent<Rectangle2D> ev) {
Rectangle2D r = ev.getData();
stage.setWidth(r.getWidth());
stage.setHeight(r.getHeight());
}
});</pre>
</li>
</ul>
<p>
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"></span>也就是说,webEngine可以获得javascript的内容,以及用户的响应,实现了java程序和javascript的交互。
</p>
<p>
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; font-size: 18px;">3.文档对象入口</span>
</p>
<p>
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"></span>也就是支持dom解析
</p>
<p>
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; white-space: pre;"></span>
</p>
<ul class="blockList list-paddingleft-2" style="list-style-type: none;">
<li>
<pre style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 24px; background-color: rgb(240, 240, 240); overflow-x: auto; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(0, 0, 0); word-break: break-all;">EventListener listener = new EventListener() {
public void handleEvent(Event ev) {
Platform.exit();
}
};
Document doc = webEngine.getDocument();
Element el = doc.getElementById("exit-app");
((EventTarget) el).addEventListener("click", listener, false);</pre>
</li>
</ul>
<p>
<span style="box-sizing: border-box; outline: 0px; word-break: break-all; font-size: 18px;">4.执行javascript</span>
</p>
<p>
</p>
<pre style="box-sizing: border-box; outline: 0px; padding: 0px; margin-top: 0px; margin-bottom: 24px; background-color: rgb(240, 240, 240); overflow-x: auto; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; color: rgb(0, 0, 0); word-break: break-all;">webEngine.executeScript("history.back()");</pre>
<p>
5.就是java和javascript的交互,可以参考api
</p>
<p>
<br/>
</p>