browserType
Advanced tools
Comparing version 0.1.0 to 0.2.0
module.exports = function browserType(){ | ||
return function(req,res,next){ | ||
req.isIE = | ||
req.isIE6 = | ||
req.isIE7 = | ||
req.isIE8 = | ||
req.isIE9 = | ||
req.isIE10 = | ||
req.isChrome = | ||
req.isOpera = | ||
req.isFirefox = | ||
req.isSafari = false; | ||
var ua = req.headers['user-agent']; | ||
@@ -8,23 +20,38 @@ var bt = "" | ||
bt = 'ie6' | ||
req.isIE = true; | ||
req.isIE6 = true; | ||
}else if(ua.indexOf('MSIE 7') !=-1){ | ||
bt = 'ie7' | ||
req.isIE = true; | ||
req.isIE7 = true; | ||
}else if(ua.indexOf('MSIE 8') != -1 ){ | ||
bt = 'ie8' | ||
req.isIE = true; | ||
req.isIE8 = true; | ||
}else if(ua.indexOf('MSIE 9') != -1){ | ||
bt = 'ie9' | ||
req.isIE = true; | ||
req.isIE9 = true; | ||
}else if(ua.indexOf('MSIE 10') != -1){ | ||
bt = 'ie10' | ||
req.isIE = true; | ||
req.isIE10 = true; | ||
}else if(ua.indexOf('Chrome') != -1){ | ||
bt = 'chrome' | ||
req.isChrome = true; | ||
}else if(ua.indexOf('Chrome') == -1 && ua.indexOf('Safari') != -1){ | ||
bt = 'safari' | ||
req.isSafari = true; | ||
}else if(ua.indexOf('Firefox') != -1){ | ||
bt = 'firefox' | ||
req.isFirefox = true; | ||
}else if(ua.indexOf('Opera') != -1){ | ||
bt = 'opera' | ||
req.isOpera = true; | ||
} | ||
req.browserType = bt; | ||
req.browser = req.browserType = bt; | ||
next(); | ||
} | ||
} |
@@ -5,3 +5,3 @@ { | ||
"description": "to determine the browser type, this is a middleware of connect.", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/brighthas/browserType-connect", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -8,2 +8,6 @@ browserType-connet | ||
npm install browserType | ||
or | ||
cd node_modules | ||
@@ -21,3 +25,3 @@ git clone https://github.com/brighthas/browserType-connect.git browserType | ||
app.get('/',function(req,res){ | ||
res.send(req.browserType) | ||
res.send(req.browserType) // or req.browser | ||
}) | ||
@@ -35,1 +39,19 @@ | ||
# API | ||
# req.isIE | ||
# req.isIE6 | ||
# req.isIE7 | ||
# req.isIE8 | ||
# req.isIE9 | ||
# req.isIE10 | ||
# req.isChrome | ||
# req.isFirefox | ||
# req.isSafari | ||
# req.browser | ||
# req.browserType | ||
4071
52
55