Open hyperlink in another web view control

java, javafx, javafx-2, swing, webview

Solution

Allow webviewA to open content in webviewB

Use setCreatePopupHandler:

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

Or, if you are using jdk8 and don't like typing:

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

Make your html links open content in a new window

Define the hyperlinks in the document loaded in `webviewA` using `target="_blank"`

For example:

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

when you click on the hyperlink and utter the magic word, it will open the Colossal Cave adventure in `webviewB`.

Problem

I want to open link in another web view control on clicking the hyperlinks in another web view in swing using Java FX 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

Original source