用JavaScript如何找到网页浏览器的名称和版本?

王林
发布: 2023-09-19 17:37:02
转载
886 人浏览过

用JavaScript如何找到网页浏览器的名称和版本?

要查找网络浏览器的名称和版本,您需要尝试以下代码 -

示例

<html>
   <head>
      <title>Browser Detection Example</title>
   </head>
   <body>
      <script>
         <!--
            var userAgent = navigator.userAgent;
            var opera = (userAgent.indexOf(&#39;Opera&#39;) != -1);
            var ie = (userAgent.indexOf(&#39;MSIE&#39;) != -1);
            var gecko = (userAgent.indexOf(&#39;Gecko&#39;) != -1);
            var netscape = (userAgent.indexOf(&#39;Mozilla&#39;) != -1);
            var version = navigator.appVersion;

            if (opera) {
               document.write("Opera based browser");
               // Keep your opera specific URL here.
            }
            else if (gecko) {
               document.write("Mozilla based browser");
               // Keep your gecko specific URL here.
            }
            else if (ie) {
               document.write("IE based browser");
               // Keep your IE specific URL here.
            }
            else if (netscape) {
               document.write("Netscape based browser");
               // Keep your Netscape specific URL here.
            } else {
               document.write("Unknown browser");
            }
            // You can include version to along with any above condition.
            document.write("<br /> Browser version info : " + version );
         //-->
      </script>
   </body>
</html>
登录后复制

以上是用JavaScript如何找到网页浏览器的名称和版本?的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板