How to download script only for firefox

is there a way to upload a script file only for firefox

eg:

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

UPDATE

I did that way

 <script> if($.browser.mozilla) { jQuery.getScript("js/scriptFF.js"); } else { jQuery.getScript("js/scriptAll.js"); } </script> 
+4
source share
4 answers

Try the following:

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

for versions

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

jQuery browser

+5
source

You can create a dynamic <script> based on the 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"; 

That should do the trick!

+5
source

This should work, although if someone fakes your user agent, you can peel off:

 if (navigator.userAgent.toLowerCase().indexOf('firefox') !== -1) { var script = document.createElement("script"); script.src = "js/scriptFF.js"; script.type = "text/javascript"; } 
+1
source

In your code add:

 if (navigator.userAgent.indexOf("Firefox") != -1) { //Your firefox code } 
0
source

Source: https://habr.com/ru/post/1438611/


All Articles