首页 > 代码库 > navigator.userAgent.indexOf
navigator.userAgent.indexOf
navigator.userAgent.indexOf
<script type="text/javascript">
function getOs() {
var OsObject = "";
if (navigator.userAgent.indexOf("MSIE") > 0) {
return "MSIE";
}
if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
return "Firefox";
}
if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
return "Safari";
}
if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
return "Camino";
}
if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
return "Gecko";
}
}
alert("您的浏览器类型为:" + getOs());
switch (getOs()) {
case "Firefox":
document.write("<link rel=‘stylesheet‘ type=‘text/css‘ href=http://www.mamicode.com/‘ff.css‘ />");
break;
case "Safari":
document.write("<link rel=‘stylesheet‘ type=‘text/css‘ href=http://www.mamicode.com/‘sa.css‘ />");
break;
case "Camino":
document.write("<link rel=‘stylesheet‘ type=‘text/css‘ href=http://www.mamicode.com/‘ca.css‘ />");
break;
case "Gecko":
document.write("<link rel=‘stylesheet‘ type=‘text/css‘ href=http://www.mamicode.com/‘ge.css‘ />");
break;
default:
document.write("<link rel=‘stylesheet‘ type=‘text/css‘ href=http://www.mamicode.com/‘ie.css‘ />");
break;
}
</script>
<body onl oad=" getOs()">
navigator.userAgent.indexOf