如何指定一个按钮来打开一个网址? [英] How to specify a button to open an URL?
问题描述
我想写触发用户的默认邮件客户端发送电子邮件的Web应用程序。
I want to write a web application that triggers the default email client of the user to send an email.
因此,我创建了一个链接,从而导致符合的mailto URI方案( HTTP的网址://en.wikipedia。组织/维基/邮寄地址):
Thus, I created a Link, that leads to an URL conforming to the mailto URI scheme (http://en.wikipedia.org/wiki/Mailto):
Link emailLink = new Link("Send Email",
new ExternalResource("mailto:someone@example.com"));
然而,而是采用了链接,我想要提供一个按钮,允许以触发各自的功能。但是,对于按钮,我不能设置一个ExternalResource被打开。
However, instead of using a Link, I want to provide a Button that allows to trigger the respective functionality. But, for buttons I cannot set an ExternalResource to be opened.
是否有人知道解决这个问题的按钮,或如何创建一个链接,外观和行为完全像一个按钮?我也尝试了一些修改CCS但并不由我管理任务。我还发现以前Vaadin版本的一些解决方案( https://vaadin.com/forum/#!/thread/69989 ),但是,遗憾的是他们没有为Vaadin 7工作。
Does anybody know to solve this problem for Buttons, or how to create a Link that looks and behaves exactly like a button? I also tried some CCS modification but did not manage the task by myself. I also found some solutions for former Vaadin versions (https://vaadin.com/forum/#!/thread/69989), but, unfortunately they do not work for Vaadin 7.
推荐答案
我记得使用ResourceReference解决类似的问题。
I remember solving a similar problem using a ResourceReference.
Button emailButton = new Button("Email");
content.addComponent(emailButton);
Resource res = new ExternalResource("mailto:someone@example.com");
final ResourceReference rr = ResourceReference.create(res, content, "email");
emailButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Page.getCurrent().open(rr.getURL(), null);
}
});
这篇关于如何指定一个按钮来打开一个网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!