Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AccessingWebPageAndBrowserInformation.asciidoc 1.7KB

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