Programmatic click-through

I have an object of the Hyperlink class. I want to use a button to click on the link, not a link, i.e. the reaction to clicking on the button is to click on the link.

final Hyperlink link = new Hyperlink(name, name);
Button btn = new Button(link.getHTML());
btn.addClickHandler(new ClickHandler() {            
    @Override
     public void onClick(ClickEvent event) {
         Window.open("#"+link.getText(), null, null);               
     }
});

This code works, but opens a new browser window. How do I make the transition appear in the current window? Maybe you need to pass an event for a link?

 1
Author: Nicolas Chabanovsky, 2011-02-16

2 answers

Instead of

Window.open("#"+link.getText(), null, null);

Use

window.location.replace(link.getText())
 3
Author: WiT, 2011-02-16 11:48:11

It is strange to pass null as a parameter for opening the page, in this case, the result is generally unpredictable.

Window.open(link, "_self", "");

Hyperlink-deprecated class, better use Anchor:

Anchor anchor = new Anchor();
anchor.setTarget("_self");
anchor.setHref(link);

In no case should you start writing native code because of such a problem!

 3
Author: Nicolas Chabanovsky, 2011-02-21 20:15:43