Search code examples
javascriptinternet-explorer-6

Prevent javascript include in IE6


I would love to hear your thoughts on this particular problem:

I'm using LinkedIn's button functionality and it comes likes this:

<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/MemberProfile" data-id="http://www.linkedin.com/pub/profile" data-format="click" data-text="LinkedIn Profile"></script>

The only problem is that it renders very poorly in IE6, so all I want to do is to hide that button in IE6, I've thought about using the <!--[if gte IE 7]>Javascript code here<![endif]--> but that would also prevent it from loading in any other browser than IE, an other option would be to use the jquery: if($.browser.msie && $.browser.version=="6.0"){ } but how do I do that with SRC javascript files?

Any thoughts? Thanks!


Solution

  • You say you tried this:

    <!--[if gte IE 7]>Javascript code here<![endif]-->
    

    As you say, this will prevent non-IE browsers from seeing the script.

    But there is a way of specifying conditional comments that will be ignored by other browsers. All you need to do is drop the hyphens that make it a comment, like this:

    <![if gte IE 7]>Javascript code here<![endif]>
    

    This will now work in all browsers, except IE prior to IE7.

    See http://en.wikipedia.org/wiki/Conditional_comment for more.

    (by the way, off topic, and I'm sure you've heard this a million times already, but I would seriously recommend dropping support for IE6 -- there's virtually no-one still using it any more)