Hide an html element using javascript only if browser is firefox

前端 未结 6 1766
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 07:28

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

6条回答
  •  -上瘾入骨i
    2021-01-05 08:14

    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.

提交回复
热议问题