Browser compatibility with javascript

Asked

Viewed 1,306 times

2

Is there any tool or method to recognize which browser the user is using and whether this is compatible with the version of JS and Jquery that exists on my system ?

The idea is if not compatible, alert the user and block the system.

3 answers

0


The doubt was based on whether the client’s browser was compatible with the javascript features the system used. The library was used to solve the problem Modernizr Same as the support for checking the features the browser supports.

0

To detect which browser and its respective version, you can use the following function, where an object will be returned with the browser name, its version and other browser information:

    // Opera 8.0+
var opera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
    // Firefox 1.0+
var firefox = typeof InstallTrigger !== 'undefined';
    // At least Safari 3+: "[object HTMLElementConstructor]"
var safari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
    // Internet Explorer 6-11
var ie = /*@cc_on!@*/false || !!document.documentMode;
    // Edge 20+
var iedge = !isIE && !!window.StyleMedia;
    // Chrome 1+
var chrome = !!window.chrome && !!window.chrome.webstore;
    // Blink engine detection
var blink = (isChrome || isOpera) && !!window.CSS;

To detect which browser and its respective version, you can use the following function, where an object will be returned with the browser name, its version and other browser information:

function get_browser(){
    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 {name:'IE',version:(tem[1]||'')};
        }   
    if(M[1]==='Chrome'){
        tem=ua.match(/\bOPR\/(\d+)/)
        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]);}
    return {
      name: M[0],
      version: M[1]
    };
 }

Source: How to know which browser version dynamically?

0

Use J-query is already a strategy for the code javascript run in multiple browsers even the old ones, but of course there are some exceptions like when the browser is prehistoric or when the user disables the javascript, an alternative to these cases is to use the no-script, example...

<!DOCTYPE html>
<html>
<body>

<script>
document.write("Hello World!")
</script>
<noscript>Desculpe! esse navegador não suporta javascript</noscript>

<p>Esse navegador suporta javascript</p>
 
</body>
</html>

Reference W3schools

Browser other questions tagged

You are not signed in. Login or sign up in order to post.