开发者

find browser user is using in web2py

hi web2py newbie here how do i get information which browser user is using ..using web2py

i am trying below code

browser=request.env.http_user_agent

but giving me result like

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24

but I am only using chrom开发者_开发百科e here how do i get that?


thanks zoer that doesnot worked for me.

i was thinking to identify it using javascript and send to controller function i also want identify operating system as well

i have found this way through which u can send values to controller but i am not geting how to use it

$.post(CONTROLLER_URL, {'browser': chrome}, function HANDLER)) and will get this value in request.vars.browse

but i am geting how to use it..is anyone know how to use $.post?


You will always get results like that, because it's how the browsers' engines are identified (see user-agent article on Wikipedia).

You have to manually parse the user-agent string, something like:

if 'Chrome' in browser:
  users_browser = 'chrome'


In new versions 2.* every request includes browser info by calling request.user_agent()

That function uses:

from gluon.contrib import user_agent_parser

Example info:

browser :   name    :   Firefox
        version :   15.0.1
is_mobile:  False
is_tablet:  False
os  :   name    :   Windows
        version :   NT 6.1

This info is always in session._user_agent

So you can check:

if session._user_agent['browser']['name']=='Chrome':
    ...your code


I think you should do what Zaur has suggested assuming all you want to detect is Chrome. Otherwise you can check httpagentparser

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜