Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Xinsheng Robert Chen
Browser detection
5. Juni 2012 10:29
Antwort

Xinsheng Robert Chen

Rang: Junior Member

Nachrichten: 45

Eintrittsdatum: 30. März 2010

Neue Beiträge

Hi,

In Liferay portal 6.0 SP1, I can use the following code to get the browser information:

#set ($browserInfo = $request.get('attributes').get('User-Agent'))
#if ($browserInfo && $browserInfo.indexOf('msie 9') > 0)
... ...
#end

In Liferay portal 6.1.10, the content of "$request" is as follows -- it no longer contains the browser information.

com.liferay.portal.kernel.servlet.ProtectedServletRequest@113e2e0

However, there is a "$browserSniffer" for browser detection. It can be used as follows.

#set ($itIsChrome = $browserSniffer.isChrome($request))
#set ($itIsSafari = $browserSniffer.isSafari($request))

But when I was testing our Liferay portal site with Chrome 19.0, The "$browserSniffer" says that the browser is both Safari and Chrome.

#if($itIsSafari && $browserMajorVersion >= 5.0)
<strong>Safari >= 5.0</strong>
#end
#if($itIsChrome && $browserMajorVersion >= 14.0)
<strong>Chrome >= 14.0</strong>
#end

The output is:

Safari >= 5.0 Chrome >= 14.0

Do you know if there is something wrong? Or I am using the API in a wrong way?

Thanks!
Jelmer Kuperus
RE: Browser detection
5. Juni 2012 14:45
Antwort

Jelmer Kuperus

Rang: Liferay Legend

Nachrichten: 1190

Eintrittsdatum: 10. März 2010

Neue Beiträge

My chrome identifies itself as :

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.53 Safari/536.5


If you look at the code for BrowserSnifferImpl it becomes obvious why you are seeing the behaviour you are seeing

You should file a bug report in jira