3

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!

5 Answers 5

3

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)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Spudley, works perfectly! I didn't know about this particular variation of the conditional comment possibility. (And I hear you about IE6.. but well, my company is using it for it's 1000 employees, and I don't have much of a choice...)
0
if(! IE6){
    var script = document.createElement("script");
    script.src = "src_to_js_file";
    document.body.appendChild(script);
}

or just use innerHTML to add the two script tags to DOM。

Comments

0

You can use jQuery's getScript method

if(!($.browser.msie && $.browser.version=="6.0"))
    $.getScript('http://platform.linkedin.com/in.js');

Comments

0
if($.browser.msie && $.browser.version=="6.0"){
  $('head').append('<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>')
}

Comments

0

Try this

<!--[if ! lte IE 6]>Javascript code here<![endif]-->

or something like this

<!--[if (!IE)|(IE gt 6)]>Javascript code here<![endif]-->

1 Comment

very close, but this will also prevent it being included on non-IE browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.