Plugin implemented using JCEF API - How to open hyperlinks in an external browser

Answered

Hi,

I have developed a plugin which uses JCEF api to render the web contents. And i was able to load the web content in to a FileEditor.

When a user click a link from the initial web page, Those pages need to be loaded in a external browser instead of the same FileEditor window. Is there any way that i can accomplish this task using the JCEF api ?

The approach that iam trying is as follows. But currently iam unable to get the Document object of the loaded HTML. Or is there any better way of doing this.

Document document = // get document object using JCEF api ;
NodeList nodeList = document.getElementsByTagName(HYPERLINK_TAG);
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
EventTarget eventTarget = (EventTarget) node;
eventTarget.addEventListener(CLICK_EVENT_TYPE, new EventListener() {
@Override
public void handleEvent(Event evt) {
EventTarget target = evt.getCurrentTarget();
HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
String href = anchorElement.getHref();
// handle opening URL outside JCEF
try {
//open in external browser
} catch (URISyntaxException e) {
LOG.error(Messages.getMessagePropertyText(
Messages.FAILED_TO_OPEN_EXTERNAL_BROWSER) + href);
}
}
}, false);
}

1 comment
Comment actions Permalink

Please do not crosspost between Slack and this forum.

0

Post is closed for comments.