本文整理汇总了Java中org.w3c.dom.html.HTMLAnchorElement类的典型用法代码示例。如果您正苦于以下问题:Java HTMLAnchorElement类的具体用法?Java HTMLAnchorElement怎么用?Java HTMLAnchorElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HTMLAnchorElement类属于org.w3c.dom.html包,在下文中一共展示了HTMLAnchorElement类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleEvent
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
@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();
}
}
示例2: handleEvent
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
@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();
}
示例3: handleEvent
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
@Override
public void handleEvent(Event event) {
HTMLAnchorElement anchorElement = (HTMLAnchorElement)event.getCurrentTarget();
String href = anchorElement.getHref();
if (isDesktopSupported()) {
openLinkInSystemBrowser(href);
} else {
Log.warn(APPLICATION, "OS does not support desktop operations like browsing. Cannot open link '"+href+"'!");
}
event.preventDefault();
}
示例4: redirectLinksToBrowser
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
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);
}
});
}
示例5: handleEvent
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
@Override
public void handleEvent(Event evt) {
final EventTarget target = evt.getCurrentTarget();
final HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
final String href = anchorElement.getHref();
evt.preventDefault();
JavaFXUtils.openWebpage(href);
}
示例6: handleEvent
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
@Override
public void handleEvent(Event evt) {
EventTarget target = evt.getCurrentTarget();
HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
String url = anchorElement.getHref();
// If the clicked link is downloadable
// then we prevent the browser to follow the link
// and instead we perform the download ourselves
if (downloader.isDownloadable(url)) {
downloader.download(url);
evt.preventDefault();
}
}
示例7: isLinkableElement
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
/**
* Tests if is passed Element an element which may be followed.
*
* @param element Element to be tested.
* @return True, if we can follow passed element.
*/
private static boolean isLinkableElement(Element element) {
if (element instanceof HTMLAnchorElement) {
return true;
} else if (element instanceof HTMLAreaElement) {
return true;
}
return false;
}
示例8: getTargetFromElement
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
/**
* Returns target attribute from the linkable element.
*
* @param element Linkable element.
* @return Target attribute.
*/
private static String getTargetFromElement(Element element) {
String targetAttr = null;
if (element instanceof HTMLAnchorElement) {
targetAttr = ((HTMLAnchorElement)element).getTarget();
} else if (element instanceof HTMLAreaElement) {
targetAttr = ((HTMLAreaElement)element).getTarget();
}
return targetAttr;
}
示例9: getHrefFromElement
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
/**
* Returns href attribute from the linkable element.
*
* @param element Linkable element.
* @return Href attribute.
*/
private static String getHrefFromElement(Element element) {
String targetAttr = null;
if (element instanceof HTMLAnchorElement) {
targetAttr = ((HTMLAnchorElement)element).getHref();
} else if (element instanceof HTMLAreaElement) {
targetAttr = ((HTMLAreaElement)element).getHref();
}
return targetAttr;
}
示例10: handleEvent
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
@Override
public void handleEvent(Event event) {
HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
String href = anchorElement.getHref();
try {
JabRefDesktop.openBrowser(href);
} catch (IOException e) {
LOGGER.error("Problem opening browser", e);
}
event.preventDefault();
}
示例11: initFX
import org.w3c.dom.html.HTMLAnchorElement; //导入依赖的package包/类
private static void initFX(final JFXPanel fxPanel) {
final WebView webView = new WebView();
fxPanel.setScene(new Scene(webView));
// Obtain the webEngine to navigate
final WebEngine webEngine = webView.getEngine();
webEngine.loadContent("Escapists Map Editor\n" +
"Written by jselby\nhttp://redd.it/2wacp2\n\n" +
"You don't have a map loaded currently - \nGo to File in the top left, and press a button there!\n" +
"Loading...");
webEngine.load("http://escapists.jselby.net/welcome/");
webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
@Override
public void changed(ObservableValue<? extends Worker.State> observable,
Worker.State oldValue, Worker.State newValue) {
if (newValue == Worker.State.SUCCEEDED) {
final Document document = webEngine.getDocument();
NodeList nodeList = document.getElementsByTagName("a");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
EventTarget eventTarget = (EventTarget) node;
eventTarget.addEventListener("click", new org.w3c.dom.events.EventListener() {
@Override
public void handleEvent(Event evt) {
EventTarget target = evt.getCurrentTarget();
HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
String href = anchorElement.getHref();
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(new URL(href).toURI());
} catch (Exception e) {
e.printStackTrace();
}
}
evt.preventDefault();
}
}, false);
}
}
}
});
}