0

Im using vaadin 6.8.5, I need to set the user-agent header of a browser depending upon the OS(Android,Iphone,Firefox,Chrome) the user selects. How to set a particular user agent to the browser. im using Vaadin Embedded to display the external URL . I have to set user agent to this vaadin embedded component.Please help me to come up with a solution...

Regards, M.Vignesh

  • Hmm... the user agent header comes from the user agent and not from the server. This is why it is called user agent and not server agent. Even if you use some sort of iframe to embedd a external resource, the user agent is still the user agent of the webbrowser your application is show in. – André Schild Feb 24 '14 at 07:12
  • So now how to get the user agent of the embedded browser ? Is there any way to get this? –  Feb 24 '14 at 08:36

1 Answers1

0

So now how to get the user agent of the embedded browser ? Is there any way to get this?

To get the user-agent string do the following:

Vaadin7:

WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
webBrowser.getBrowserApplication(); // Get the browser user-agent string.

Vaadin6:

WebBrowser browser = (WebBrowser) myApplication.getMainWindow().getTerminal();
nexus
  • 2,937
  • 3
  • 17
  • 22
  • Hi @nexus i need to change my browser's default agent to another user - agent. BTW Im using vaadin 6.8.5 . The above coding gives the default user agent for browser. I need to set some other user agent instead of this default value. –  Feb 24 '14 at 10:25
  • @Vignesh why do you need to change the agent? – nexus Feb 24 '14 at 10:52
  • I am loading an external url as embedded component. I need to make that external url to be visible to only android and iphone users. So i need to change the defaut agent to android or iphone agent for loading that external url as embedded browser. –  Feb 24 '14 at 10:55
  • You can't change the user agent sent by the browser from the server side. This is a read only property, so even with javascript you can't change it. So NO, you can't change the UA of the webbrowser, not in vaadin, not in any other javascript application. – André Schild Feb 24 '14 at 12:08
  • @AndréSchild Then how about this changing the user agent [link](http://stackoverflow.com/questions/2529682/setting-user-agent-of-a-java-urlconnection?rq=1) –  Feb 24 '14 at 12:18
  • 1
    @Vignesh In the link you show, the page is downloaded by java and then processed further. But if I understand you correctly, you just show the page in a embedded component, which results in a normal iframe which is resolved/requested/rendered by the webbrowser of your choice. – André Schild Feb 24 '14 at 13:52
  • @AndréSchild Then there is no option in vaadin to change the user agent compatible for android and iphone devices. Is it the conclusion or solution? –  Feb 25 '14 at 04:03
  • 2
    @Vignesh hte conclusion is, that you can't modify the user agent of the webbrowser by javascript. So vaadin can't do what you request (Nor any other web application based on JS) – André Schild Feb 25 '14 at 19:08
  • @AndréSchild Is it possible to load an external url other than embedded component so that i can set user agent header by java download? –  Feb 27 '14 at 05:45
  • @Vignesh The only way to influence the request to the external site would be to download it from the serverside, here you can specify anything you wish. But you will then have to relocate image / javascript / css urls and a lot more. – André Schild Feb 27 '14 at 10:22
  • @AndréSchild Can u provide any sample of how to achieve it? If i am getting downloaded and then setting header how to display the added header url in embedded in vaadin? –  Feb 27 '14 at 10:27
  • 1
    @Vignesh You download the html content to a local file on the server. (And at that moment you specify which UA to send to the server). Then set this file as the source of the embedded component. – André Schild Feb 27 '14 at 13:59
  • @AndréSchild Thanks for suggesting me some good solutions.Will give a try! –  Feb 28 '14 at 09:04