Button类中有.click()
方法,您可以.click()
从代码中实际点击它
Button b = new Button("b");
b.click();
我怎么能用Anchor做到这一点?我打电话给rpc,我想在新标签onSuccess();
Anchor a = new ("a", "url", "_blank");
a.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
RPC(onSuccess()){
String href = rpc.getUrl();
a.setHref(href);
a.click(); // How can I do that ?
}
}
});
答案 0 :(得分:2)
您可以使用Window.Location.assign("url");
此方法也可以帮助您:
public static native String getURL(String url)/*-{
return $wnd.open(url, 'target=_blank')
}-*/;
答案 1 :(得分:2)
以下代码段对我有用:
public static native void click(String url)
/*-{
var a = document.createElement('a');
document.body.appendChild(a);
a.href = url;
a.click();
}-*/;