java - 在另一个 Web View 控件中打开超链接

标签 java swing webview javafx-2 javafx

我想在另一个 Web View 控件中打开链接,单击另一个 Web 中的超链接 使用 Java FX 在 swing 中查看

Actually i am having two web view controls A n B on the same screen . On clicking the hyperlink in a , new link should be opened in B web view control

最佳答案

允许webviewA打开webviewB中的内容

使用setCreatePopupHandler :

webviewA.getEngine().setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
  @Override public WebEngine call(PopupFeatures popupFeatures) {
    return webviewB.getEngine();
  }
});

或者,如果您使用的是 jdk8 并且不喜欢打字:

webviewA.getEngine().setCreatePopupHandler(
  popupFeatures -> webviewB.getEngine()
);

让您的 html 链接在新窗口中打开内容

使用 target="_blank" 定义加载到 webviewA 的文档中的超链接

例如:

webviewA.loadContent(
  "<a href='http://sundae.triumf.ca/pub2/cave/node001.html' target='_blank'>" +
    "XYZZY" +
  "</a>"
);

当您单击超链接并说出魔法词时,它将在 webviewB 中打开 Colossal Cave 冒险。

关于java - 在另一个 Web View 控件中打开超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13697974/

相关文章:

java - Intellij 未检测到 Play 语法

java - JFileChooser 不会死?

java - JFileChooser 将文件名传递为 null

android - 使用网页 View 仅查看网页中的特定 div

android - android webView 中的异常

android - 在 WebView 中加载本地 html?

Java 记录和字段注释

java - arrayAdapter 导致应用程序强制关闭

java - 如何解决这个java方法中的stackoverflow异常?

java - 无法使 GridBagLayout 按预期工作