I may open a browser new tab with Anchor component configured with target=_blank
. How to do the same in Vaadin23 with the Button
component inside the ClickListener
code?
Asked
Active
Viewed 793 times
1

alexanoid
- 24,051
- 54
- 210
- 410
-
What is it that you are trying to accomplish? Could you use a link styled as a button? – Marcus Hellberg Aug 17 '22 at 22:21
-
yeah.. I love Vaadin because I don't need to deeply dive into the css :) I have a number of small buttons already, and would like to add another one for `permlink` url. Is there a simple way to style Anchor like the Button with `ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_TERTIARY` ? – alexanoid Aug 17 '22 at 22:30
-
Unfortunately, there's no built in styling right now. I thought we had, but it might have been in an earlier version. You can follow the discussion here https://github.com/vaadin/web-components/issues/1803 – Marcus Hellberg Aug 18 '22 at 02:09
-
1The same should still apply https://stackoverflow.com/a/24039630 – Knoobie Aug 18 '22 at 05:02
1 Answers
3
You can do it using UI.getCurrent().getPage().open(String url)
, which opens the URL in a new tab by default.
Button button = new Button("Click Me", e -> {
UI.getCurrent().getPage().open("https://stackoverflow.com");
});
add(button);

Tarek Oraby
- 1,199
- 6
- 11
-
1You can also add a second argument to the open() method, which specifies in which window to open it. (_blank is probably default) – André Schild Aug 19 '22 at 17:14
-
Yes, _blank is the default. You can also specify for example _self to open the page in the same browser tab: https://vaadin.com/api/platform/14.8.15/com/vaadin/flow/component/page/Page.html#open-java.lang.String-java.lang.String- – Tarek Oraby Aug 19 '22 at 18:11