본문 바로가기

Web Progreming

[ JavaScript ] 브라우저 체크

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<script type="text/javascript">
var Browser = {
    a : navigator.userAgent.toLowerCase()
}

Browser = {
    ie : /*@cc_on true || @*/ false,
    ie6 : Browser.a.indexOf('msie 6') != -1,
    ie7 : Browser.a.indexOf('msie 7') != -1,
    ie8 : Browser.a.indexOf('msie 8') != -1,
    opera : !!window.opera,
    safari : Browser.a.indexOf('safari') != -1,
    safari3 : Browser.a.indexOf('applewebkit/5') != -1,
    mac : Browser.a.indexOf('mac') != -1,
    chrome : Browser.a.indexOf('chrome') != -1,
    firefox : Browser.a.indexOf('firefox') != -1
}

function whatKindOfBrowser() {
if (Browser.chrome) {
alert("It is chrome browser");
} else if (Browser.ie6) {
alert("It is ie6 browser");
} else if (Browser.ie7) {
alert("It is ie7 browser");
} else if (Browser.ie8) {
alert("It is ie8 browser");
} else if (Browser.opera) {
alert("It is opera browser");
} else if (Browser.safari) {
alert("It is safari browser");
} else if (Browser.safari3) {
alert("It is safari3 browser");
} else if (Browser.mac) {
alert("It is mac browser");
} else if (Browser.firefox) {
alert("It is firefox browser");
} else {
alert("It is maybe ie");
}
}
</script>
</head>
<body>
<input type="button" value="브라우저 체크" onclick="javascript:whatKindOfBrowser();" />
</body>