views:

462

answers:

2

How can i detect which browser type the client is using. I have a problem where i have to ask people to use different browser (Firefox) instead of IE. How can i get this information.

I know http request has this information (Header). How will i get the navigator.appName from the view.py in the Django framework ?

+1  A: 

You can look into the 'user agent string' and parse out the values.

Here's the relevant docs, specifically on (HTTP_USER_AGENT):

http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META

Alex Sexton
+5  A: 

You can extract that information from the request object like so:

request.META['HTTP_USER_AGENT']
digitaldreamer
But with java script i can get the browser information by just doing document.write("Browser Name: " + navigator.appName); which gives Microsoft Internet Explorer . There is no direct method of getting it ? I mean i have to parse the user agent and search for MSIE .
AlgoMan
In the past I have written custom middleware to handle browser detection for stuff like mobile. If you go this rout you really need to be careful with your caching or else things will randomly fail in strange ways. If you only need to make exceptions for IE it's best to use the IE Conditional Comments http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx .
digitaldreamer
I think conditional comments are simpler :). Thanks digitaldreamer
AlgoMan