How to Detect User Browser JavaScript Programming Tutorial




Lesson Code: http://www.developphp.com/video/JavaScript/How-to-Detect-User-Browser-JavaScript-Tutorial
Learn how to detect the user browser software using JavaScript. There are various different ways to go about obtaining the result. This script is written to best convey the logic to someone new to programming. We also make special considerations for modern versions of Internet Explorer browser detection in this exercise.

Original source


31 responses to “How to Detect User Browser JavaScript Programming Tutorial”

  1. Hey is there any way to detect users internet speed using php or JavaScript and then display the website accordingly . I mean for 3g or WiFi users there will be videos and animations in the website but for 2g users or slow connection there will be text and static images. I hope u get my question. Please help me find the solution .

  2. Thanks Adam a lot
    Just noticed something:
    for instance: if you lowercase this array. say i lower case c in Chrome, it reads safari instead

    var ba = ["chrome","Firefox","Safari","Opera","MSIE"]

  3. Tried, didn't work properly, still didn't detect Edge and Vivaldi. Here is my suggested fix:
    //…/
    var ba = ["Vivaldi", "Trident", "Edge", "Chrome", "Firefox", "Safari", "Opera", "MSIE"];
    //…/
    Hope it will be helpful.

  4. WTF? this is from Edge 馃榾 — User-agent header sent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240

  5. I'd choose:

    ba.some( function( browser ) {
    if ( ua.indexOf( browser ) > -1 ) {
    b = browser;
    return true;
    }
    });

    Or:

    b = ba.filter( function( browser ) {
    return ua.indexOf( browser ) > -1
    })[0];

    Or maybe even .reduce()

  6. Just to test, I put the more common browsers like Chrome and Firebox at the end of the array and got some interesting results.
    Edge and Chrome will return Chrome or Safari depending on which is earlier in the array.

    Would Safari return only Safari and thus we have Chrome at the beginning to negate the mix-up?

Leave a Reply