mike269
(mike doe)
May 15, 2019, 3:09pm
1
Hello again! Today while i was making tests, i was wondering if its possible to get the window size of the browser. Is there any way? all methods are outdated and I found a event(UI.getCurrent().getPage().addBrowserWindowResizeListener(e->{});
) that its called every time i resize the browser but this event not works when i launch the aplication.
Thank you again!
ollit.1
(Olli Tietäväinen)
May 15, 2019, 4:05pm
2
Will be available in Vaadin 14 (already testable with Flow 2.0.0.beta1): https://github.com/vaadin/flow/issues/4320
mike269
(mike doe)
May 17, 2019, 8:04am
4
In agreement! there is a way, with this tutorial [https://vaadin.com/tutorials/calling-java-from-javascript ]
(https://vaadin.com/tutorials/calling-java-from-javascript ), I could call a javascript function which calls a java function but passing the window.innerWidth
as an argument, something like this:
.java
getElement().executeJavaScript("javascriptFunction($0)", getElement());
@ClientCallable
private void javaFunction(int width){
System.out.println(width)
}
.js
function javascriptFunction(element) {
element.$server.javaFunction(window.innerWidth);
}
Steven110
(Steven Z)
October 7, 2019, 3:05pm
5
Just following up with syntax for doing this in vaadin 14 in case anyone else stumbles on this:
UI.getCurrent().getPage().retrieveExtendedClientDetails(details -> {
windowWidth = details.getWindowInnerWidth();
});
UI.getCurrent().getPage().addBrowserWindowResizeListener(event -> {
windowWidth = event.getWidth();
});