Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load script only for firefox

is there a way to load script file only for FireFox

for example:

<script src="js/script.js"></script>

<script src="js/scriptFF.js"></script> - this only for firefox ??

UPDATE

I made in this way

<script>
    if($.browser.mozilla) { 
        jQuery.getScript("js/scriptFF.js");
    } else {        
        jQuery.getScript("js/scriptAll.js");            
    }
</script>
like image 260
gidzior Avatar asked Oct 09 '12 09:10

gidzior


2 Answers

You can create a <script> tag dynamically checking based on User Agent.

var ffFlag = (navigator.userAgent.toLowerCase().indexOf('firefox') !== -1);
var script = document.createElement("script");
script.src = (ffFlag)?"js/scriptFF.js":"js/script.js";
script.type = "text/javascript";

This should do the trick!

like image 67
Nokia808Freak Avatar answered Sep 18 '22 02:09

Nokia808Freak


Try this:

if($.browser.mozilla) {
  // do something
}

for versions

if ($.browser.mozilla && $.browser.version >= "2.0" ){
   alert('Mozilla above 1.9');
}

jQuery Browser

like image 33
Dipak Avatar answered Sep 18 '22 02:09

Dipak