Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting User Agent Firefox [duplicate]

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>
like image 532
user2062745 Avatar asked Feb 12 '13 23:02

user2062745


1 Answers

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

like image 156
Samsquanch Avatar answered Sep 30 '22 01:09

Samsquanch