How to click an anchor from code in GWT?

In the Button class, there is a method .click()that you can .click()from the code that did not physically click on it.

Button b = new Button("b");
b.click();

How can I do this with Anchor? I call rpc and I want to open it in a new tabonSuccess();

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 ?
           }

   }
});
+3
source share
2 answers

you can use Window.Location.assign("url");

Also this method can help you:

public static native String getURL(String url)/*-{
        return $wnd.open(url, 'target=_blank')
    }-*/;
+2
source

The following code snippet works for me:

public static native void click(String url)
/*-{

    var a = document.createElement('a');
    document.body.appendChild(a);
    a.href = url;
    a.click();

}-*/;
+2
source

Source: https://habr.com/ru/post/1785361/


All Articles