Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide an html element using javascript only if browser is firefox

How can I hide a div with javascript if the browser is firefox only?

like image 842
Cameron Avatar asked Mar 16 '10 13:03

Cameron


2 Answers

To check Firefox browser

//Javascript
var FIREFOX = /Firefox/i.test(navigator.userAgent);

if (FIREFOX) {
  document.getElementById("divId").style.display="none";
}


<!-- HTML-->
<div id="divId" />
like image 163
Buhake Sindi Avatar answered Sep 21 '22 20:09

Buhake Sindi


Just check a FF-specific JavaScript property. E.g.

var FF = (document.getBoxObjectFor != null || window.mozInnerScreenX != null);

if (FF) {
    document.getElementById("divId").style.display = 'none';
}

This is called feature detection which is preferred above useragent detection. Even the jQuery $.browser API (of which you'd have used if ($.browser.mozilla) for) recommends to avoid useragent detection.

like image 44
BalusC Avatar answered Sep 20 '22 20:09

BalusC