How to detect browser type and its version

后端 未结 5 1990
借酒劲吻你
借酒劲吻你 2021-02-03 21:54

how can i detect browser type and its version in Rails. I want to put check on the version of specific browser and if its not required browser version than ask user to upgrade i

5条回答
  •  时光取名叫无心
    2021-02-03 22:41

    Though this is a frontend solution, I prefer to check for a specific feature that is required, such as flexbox. You can use something like Modernizr, or just a simple JavaScript check will do (https://stackoverflow.com/a/27047981/179311).

    if(!("flexWrap" in document.documentElement.style)) {
        // IE 10, Chrome 20 and Firefox 27 and anything older will hit this.
        alert('your browser is out of date');
        // maybe this is preferred
        // window.location = '/browser-unsupported'
    }
    

提交回复
热议问题