Skip to content

Instantly share code, notes, and snippets.

@mitchellrj
Created January 24, 2012 14:58
Show Gist options
  • Save mitchellrj/1670561 to your computer and use it in GitHub Desktop.
Save mitchellrj/1670561 to your computer and use it in GitHub Desktop.
Internet Explorer detection
def is_ie(request, min_version=None, max_version=None):
user_agent = request.environ.get('HTTP_USER_AGENT', '')
ie = user_agent.find('MSIE')
if ie==-1:
return False
if not min_version and not max_version:
return True
version_match = re.match('[\d\.]*', user_agent[ie+5:])
if not version_match:
return False
version = tuple(map(int, version_match.group(0).split('.')))
result = True
if min_version:
result = result and version >= min_version
if max_version:
result = result and version <= max_version
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment