Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open hyperlink in another web view control

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

like image 583
Adesh singh Avatar asked Jun 19 '26 13:06

Adesh singh


1 Answers

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.

like image 165
jewelsea Avatar answered Jun 21 '26 02:06

jewelsea