日期:2014-05-16  浏览次数:20332 次

用 JS 判断 浏览器 类型

<script type="text/javascript">
?function getBrowserName() {?
??var browserName = "";
??if(navigator.userAgent.indexOf("MSIE") > 0) {
???browserName = "MSIE";
??}
??if(isFirefox = navigator.userAgent.indexOf("Firefox")>0){
??? browserName = "Firefox";
??}
??if(isSafari = navigator.userAgent.indexOf("Safari")>0) {
??? browserName = "Safari";
??}?
??if(isCamino = navigator.userAgent.indexOf("Camino")>0){
??? browserName = "Camino";
??}
??if(isMozilla = navigator.userAgent.indexOf("Gecko/")>0){
??? browserName = "Gecko";
??}
??return browserName;
?}

function test() {
?var browserName = getBrowserName();
?alert("Browser is :: " + browserName);
}
</script>

<input type="button" name="test" value="test" onclick="test()" />