How to add and run a javascript for only on firefox not on oth开发者_如何学编程ers?
I've to add a javascript on a page and it should only work on firefox. not on IE
Never use browser detection, use object detection (if your intent was using some objects/methods available only on some browsers.)
use navigator object
navigator.appName
Returns the official name of the browser.
Aside from using navigator.appName
, you could use the browser detection script from Quirksmode, then use an if statement to check if it's Firefox. This will nicely prepare browser information in an object for you, so you can pick out individual information such as version number, etc.
精彩评论