如何在asp.net中的javascript或jquery中获取浏览器名称? [英] How to get browser name in javascript or jquery in asp.net ?

查看:71
本文介绍了如何在asp.net中的javascript或jquery中获取浏览器名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
如何在javascript或jquery及其版本中获取浏览器名称,

i需要检查以下浏览器,如IE 10,IE 11,Chrome,Mozila和opera。 br />


我有代码,但是如果我在IE11中打开,它会将浏览器名称显示为Mozila.i我需要代码来自

http://www.w3schools.com/js/js_window_navigator.asp [ ^ ]





navigator.appName在所有浏览器中返回Netscape

navigator.appCodeName在所有浏览器中返回Mozilla





注意:对于IE它显示Netscape,它是否正确?



这里我附上ie的屏幕截图,为此我从下面链接获取代码,



https://cube3x.com/get -browser的名称和版本,我们ing-pure-javascript / [ ^ ]



为mozila和chrome它显示正确的名称,如果我在chrome中运行它显示Chrome,42.0.2311.90为mozila它显示Firefox,37.0





截图 [< a href =http://prntscr.com/6we3xftarget =_ blanktitle =New Window> ^ ]





问候

Aravind

Hi How to get browser name in javascript or jquery and its version also,
i need to check in following browsers like IE 10,IE 11 ,Chrome ,Mozila and opera.

I have code but if i open in IE11,it show browser name as Mozila.i am take code from
http://www.w3schools.com/js/js_window_navigator.asp[^]


navigator.appName in all browser it return Netscape
navigator.appCodeName in all browser it return Mozilla


Note: for IE it show Netscape,is it correct ?

here i attach screenshot of ie ,for this i get code from below link,

https://cube3x.com/get-browser-name-and-version-using-pure-javascript/[^]

for mozila and chrome it show correct name like if i run in chrome it show Chrome,42.0.2311.90 for mozila it show Firefox,37.0


screenshot[^]


Regards
Aravind

推荐答案

您可以使用 jQuery Browser Plugin [ ^ ]。



请参阅用法 [ ^ ] 。
You can use Plugins like jQuery Browser Plugin[^].

See the Usage[^].


<html>
<head>
    <script>
        navigator.sayswho = (function () {
            var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];

            if (/trident/i.test(M[1])) {
                tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
                //return 'IE ' + (tem[1] || '');
                return { name: 'IE ', version: (tem[1] || '') };
            }

            if (M[1] === 'Chrome') {
                tem = ua.match(/\bOPR\/(\d+)/);
                //if (tem != null) return 'Opera ' + tem[1];
                if (tem != null) { return { name: 'Opera', version: tem[1] }; }
            }

            M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];

            if ((tem = ua.match(/version\/(\d+)/i)) != null) {
                M.splice(1, 1, tem[1]);
            }
            alert('Browser Name: ' + M.join(' and Version # '));
            return M.join(' ');
        })();
    </script>
</head>
<body>
</body>
</html>





我一直在寻找相同的解决方案。它可能对你有所帮助。

参考网站:http://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser



I was looking for the same and came across above solution. It might be helpful to you.
Ref. site: http://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser


这篇关于如何在asp.net中的javascript或jquery中获取浏览器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆