Created
January 24, 2012 14:58
-
-
Save mitchellrj/1670561 to your computer and use it in GitHub Desktop.
Internet Explorer detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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