You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AccessingWebPageAndBrowserInformation.asciidoc 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ---
  2. title: Accessing Web Page And Browser Information
  3. order: 27
  4. layout: page
  5. ---
  6. [[accessing-web-page-and-browser-information]]
  7. = Accessing web page and browser information
  8. Vaadin 7 includes a new *Page* class offering access to various
  9. client-side information and events concerning the web page and browser
  10. window in which the Vaadin UI resides. The Page instance corresponding
  11. to a given UI is accessed via the `getPage()` method of the UI or using
  12. a static method `Page.getCurrent()`.
  13. You can access the browser window size and add size change listeners:
  14. [source,java]
  15. ....
  16. Page page = someUI.getPage();
  17. page.addBrowserWindowResizeListener(new BrowserWindowResizeListener() {
  18. public void browserWindowResized(BrowserWindowResizeEvent event) {
  19. Notification.show("Window width=" + event.getWidth() + ", height=" + event.getHeight());
  20. }
  21. });
  22. ....
  23. You can access the optional fragment part of the location URI and add
  24. fragment change listeners:
  25. [source,java]
  26. ....
  27. page.setUriFragment(page.getUriFragment() + "foo");
  28. page.addUriFragmentChangedListener(new UriFragmentChangedListener() {
  29. public void uriFragmentChanged(UriFragmentChangedEvent event) {
  30. Notification.show("Fragment=" + event.getUriFragment());
  31. }
  32. });
  33. ....
  34. You can access client browser details:
  35. [source,java]
  36. ....
  37. Notification.show("IP" + browser.getAddress() +
  38. "User-Agent:" + browser.getBrowserApplication() +
  39. "Linux: " + browser.isLinux());
  40. ....
  41. https://demo.vaadin.com/sampler/#foundation/advanced/browser-information[Live
  42. Demo]
  43. Note: If you are using a reverse proxy, you must get the value
  44. `X-Forwarded-For` from request headers. You cannot get a browser name,
  45. but you can check which browser are using.