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

ID:10652 / 打印

用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>
上一篇: HTML5允许您在浏览器内与本地客户端文件进行交互吗?
下一篇: 使用CSS将flex项目对齐到容器的中心

作者:admin @ 24资源网   2024-09-27

本站所有软件、源码、文章均有网友提供,如有侵权联系308410122@qq.com

与本文相关文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。