Firefox User Agent Discovery

I am very new to Javascript. What I found out is just a code game.

I'm having trouble downloading. Bascially I need a specific 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> 
+4
source share
1 answer

You probably shouldn't do it this way, but if you're absolutely sure you want to target firefox:

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

fiddle

+6
source

All Articles