开发者

How can I hide like button or div from Firefox?

I am building a web page and I have included Facebook's Like button. Works great in all browsers but not in Firefox. When clicked in Firefox, it creates an endless loop of opening and closing a facebook login window. This is a known issue that Facebook isn't looking like it will correct anytime soon.

Can anyone tell me what code I might write to hide the like button (or a div containing the like button) from Firefox only? I've never written code to detect a browser and 开发者_开发百科then have my site function a certain way. Not a javascript guru here. Thanks!


You can do this using the navigator javascript object, but it sounds like you have deeper problems if the facebook like button is causing an endless loop of window loads. You most probably have other errors in your code. The button should work fine in firefox.

Here's how to text for firefox using the navigator object,

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
   // user using firefox
}

This code parses the userAgent string, the string that defines the user's browser, of the navigator object. It looks for a string of the format Firefox/x.x or Firefox x.x.


This should work for you

<div id="likeDiv">
    my div
</div>
<script>
    if (navigator.userAgent.indexOf("Firefox")!=-1)
    {
        // Remove the element from the dom
        var Node1 = document.getElementById('likeDiv');
        Node1.removeChild(Node1.childNodes[0]);
    }
</script>

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜