Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用appCodeName检测浏览器并加载一些css_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 使用appCodeName检测浏览器并加载一些css

Javascript 使用appCodeName检测浏览器并加载一些css,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想检测浏览器&然后我需要根据浏览器加载css文件。为此,我使用以下javascript。但问题是,我使用的任何浏览器都会将Mozilla显示为代码名 <script type="text/javascript"> browsername=navigator.appCodeName; alert(browsername); //<- always alert Mozilla if i run in IE or Safari </script> browserna

我想检测浏览器&然后我需要根据浏览器加载css文件。为此,我使用以下javascript。但问题是,我使用的任何浏览器都会将Mozilla显示为代码名

<script type="text/javascript">
browsername=navigator.appCodeName;
alert(browsername); //<- always alert Mozilla if i run in IE or Safari
</script>

browsername=navigator.appCodeName;

警报(浏览器名称)// 您可以使用条件注释加载CSS文件:

<p class="accent">
<!--[if IE]>
According to the conditional comment this is IE<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is IE 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is IE 7<br />
<![endif]-->
<!--[if IE 8]>
According to the conditional comment this is IE 8<br />
<![endif]-->
<!--[if IE 9]>
According to the conditional comment this is IE 9<br />
<![endif]-->
<!--[if gte IE 8]>
According to the conditional comment this is IE 8 or higher<br />
<![endif]-->
<!--[if lt IE 9]>
According to the conditional comment this is IE lower than 9<br />
<![endif]-->
<!--[if lte IE 7]>
According to the conditional comment this is IE lower or equal to 7<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is IE greater than 6<br />
<![endif]-->
<!--[if !IE]> -->
According to the conditional comment this is not IE 5-9<br />
<!-- <![endif]-->
</p>

示例:

还有html标记可用于检查IE:

    <!--[if IE]>
         <link rel="stylesheet" type="text/css" href="internet_explorer_styling.css" />
    <![endif]-->

如果使用javascript,那么应该检查这些字符串中是否有一个包含chrome、firefox、opera或ie(ie=msie)

希望这对你有帮助

祝你好运

“一些浏览器错误识别自己以绕过站点测试”:

试着看看这个:

要使用IE特定的css,您可以使用内嵌css或链接样式表在头部执行类似操作:

<!--[if IE]>
  <style type="text/css">
    .selector {
      color: #000;
    }
  </style>
  <link rel="stylesheet" href="IEstyle.css">
<![endif]-->


您还可以执行特定的IE版本,例如[如果lte IE9]将是如果小于或等于IE9。[如果gt IE9]将大于IE9,依此类推。

我使用document.documentMode检查IE=undefined document.documentMode显示IE运行的版本。 但您也可以查找(ScriptEngine()=“JScript”) 还有很多重要人物 例如,枚举器是在JScript中定义的,它允许遍历数据文件系统 ActiveXObject是在JScript中定义的

如果(枚举数的类型==“函数”&&typeof-ActiveXObject==“函数”),您有IE,因此n

IE10(或可能11)停止关注条件注释。
navigator.userAgent
navigator.appVersion
<!--[if IE]>
  <style type="text/css">
    .selector {
      color: #000;
    }
  </style>
  <link rel="stylesheet" href="IEstyle.css">
<![endif]-->