Detecting User Agent Firefox

14,117

You probably shouldn't be doing it like this, but if you are absolutely sure you only want to target Firefox:

var browser = navigator.userAgent.toLowerCase();
if (browser.indexOf('firefox') > -1) {
    alert('Firefox');
}

fiddle

Share:
14,117
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    I'm pretty new to Javascript. What I've learned is from just playing around with code.

    I'm having trouble getting this to load. Bascially I need a certain div to only show in Firefox. Here is what I have.

    <div id="parent" class="control-group"></div>
    
    <script type="text/javascript">
            $(document).ready(function() {
            switch ( BrowserDetect.browser )
            {
            case 'Firefox':
                $("button[name='btn']").click(function() {
                    $("#parent").html("<div></div>");
                });
            });
            break;
            }
    </script>