org.w3c.dom.html.HTMLAnchorElement Java Examples

The following examples show how to use org.w3c.dom.html.HTMLAnchorElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HyperlinkRedirectListener.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(Event event) {
    HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
    String href = anchorElement.getHref();

    boolean done = false;
    try {
        if(Desktop.isDesktopSupported()) {
            openLinkInSystemBrowser(href);
            done = true;
        } else {
            LOGGER.warn("OS does not support desktop operations like browsing. Cannot open link '{}'.", href);
        }
    } catch(URISyntaxException | IOException e) {
        LOGGER.warn("OS does not support desktop operations like browsing. Failed open link '{}'.", href, e);
    }
    if(done) {
        event.preventDefault();
    }
}
 
Example #2
Source File: HyperlinkRedirectListener.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
    HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
    String href = anchorElement.getHref();

    if (Desktop.isDesktopSupported()) {
        openLinkInSystemBrowser(href);
    } else {
        LOGGER.warning("OS does not support desktop operations like browsing. Cannot open link '{" + href + "}'.");
    }

    event.preventDefault();
}
 
Example #3
Source File: MdSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void redirectLinksToBrowser(WebEngine webEngine) {
    webEngine.getLoadWorker().stateProperty().addListener(
            (ov, oldState, newState) -> {
                // adjust link handling
                if (webEngine.getDocument() == null)
                    return;

                NodeList nodeList = webEngine.getDocument().getElementsByTagName("a");
                for (int i = 0; i < nodeList.getLength(); i++) {
                    Node node = nodeList.item(i);
                    EventTarget eventTarget = (EventTarget) node;

                    eventTarget.addEventListener("click", evt -> {
                        EventTarget target = evt.getCurrentTarget();
                        HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
                        String href = anchorElement.getHref();

                        //handle opening URL outside JavaFX WebView
                        try {
                            Desktop.getDesktop().browse(new URI(href));
                        } catch (IOException | URISyntaxException e) {
                            e.printStackTrace();
                        }
                        evt.preventDefault();
                    }, false);
                }
            });
}