我是JS的新手,每当有人使用Interent Explorer浏览器进入我的网站时,我都需要检测.所以,我做了下面的代码和我创建了其他Web浏览器被脚本股利我认为问题是与.getElementById或此类.所以在谈话之后,这里是代码:
<html>
<head>
<script type="text/javascript">
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
document.getElementById("example");
}
</script>
</head>
<body>
<div id ="example">You're Using Interent Explorer. </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助者.
这些HTML注释仅由Internet Explorer呈现
<body>
<!--[if IE]>
<div id ="example">You're Using Interent Explorer. </div>
<![endif]-->
</body>
Run Code Online (Sandbox Code Playgroud)
大部分时间用于CSS,因为你可以针对IE 6,7,8等等或大于IE 7:
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)