Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a function for browser detection #12

Open
ryndel opened this issue Mar 19, 2013 · 1 comment
Open

Create a function for browser detection #12

ryndel opened this issue Mar 19, 2013 · 1 comment

Comments

@ryndel
Copy link
Member

ryndel commented Mar 19, 2013

Note: This should not be used for critical functionality as browser detection is considered unreliable. It is considered best practice to use feature detection rather than browser detection.

Here's an example of usage:

var browser = (navigator.userAgent.toLowerCase());
    // console.log(browser);

    if (browser.search(/chrome/g) > -1) {
        console.log(browser.search(/chrome/g));
        $("#page-resethome .browser-alert").hide();
        $("#chrome-select").addClass("active");
        $("#browser-show #chrome").show();

    } else if (browser.search(/safari/g) > -1) {
        $("#page-resethome .browser-alert").hide();
        $("#safari-select").addClass("active");
        $("#browser-show #safari").show();

    } else if (browser.search(/firefox/g) > -1) {
        $("#page-resethome .browser-alert").hide();
        $("#firefox-select").addClass("active");
        $("#browser-show #firefox").show();

    } else if (browser.search(/msie/g) > -1) {
        $("#page-resethome .browser-alert").hide();
        $("#ie-select").addClass("active");
        $("#browser-show #ie").show();
    } else {
        $("#page-resethome .browser-alert").show();
    }
@tracend
Copy link
Member

tracend commented Mar 20, 2013

I agree it's rather trivial and to be avoided but there are uses for detecting a specific environment.

After some research, these libs seem to be doing something similar:
https://github.com/g13n/ua.js/blob/master/src/ua.js
https://github.com/tajjyarden/bacon.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants