6

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>
user2062745
  • 61
  • 1
  • 1
  • 3
  • 6
    Don't browser detect. Feature detect. – John Conde Feb 12 '13 at 23:20
  • 3
    Please explain what the "real" problem is you're trying to solve so we can suggest something better than browser detection. You should NOT be detecting a particular browser. It's much better to detect if a particular feature is present or not as that will work forever, even if the browser changes in the future. – jfriend00 Feb 12 '13 at 23:23
  • There are some browser-specific features that are hard to detect. For example subpixel rendering - Firefox does not support it (in opposite to other major browsers) and there is no function to detect it - at least from what I know... – Ján Janočko Dec 10 '18 at 07:54

1 Answers1

11

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

informatik01
  • 16,038
  • 10
  • 74
  • 104
Samsquanch
  • 8,866
  • 12
  • 50
  • 89