Hi all,
Was just wondering whether vaadin has a way of doing browser detection and redirecting to a view that displays the content for a mobile browser using say TouchKit, such that a web browser and an xhtml browser can view the page but with some modifications made to the markup so thats its viewable from a mobile device, say an Iphone.Is such functionality available ?
Notice that you can only do redirection from a Vaadin application once it has started, which may be too late for redirection for lighter pages such as for mobile browsers. You might instead want to do the redirection with JavaScript from a loader page that first checks the browser and then loads the client-side engine of Vaadin. See the Book on
embedding Vaadin applications (the section is slightly outdated).
Most of the examples in this thread are 4-5 years old, back when Vaadin was still called It Mill Toolkit.
For an example for the current version have a look at the sampler here
http://demo.vaadin.com/sampler/#foundation/browser-information and click on the Source icon in the top right.
Just noticed that they didn’t include the code for actually getting the Browser name + version… so here is my short coded version to explain it a bit:
//get the Webbrowser object
WebBrowser browser = UI.getCurrent().getPage().getWebBrowser();
//returns the user agent string. not that descriptive in some cases
browser.getBrowserApplication();
//get the Version of the Browser
browser.getBrowserMajorVersion();
browser.getBrowserMinorVersion();
//Detecting the browser this way often brings better results then using the user agent
String browserText = "";
if(browser.isChrome())
browserText = "Google Chrome";
else if (browser.isFirefox())
browserText = "Mozilla Firefox";
else if (browser.isIE())
browserText = "Internet Explorer";
....