General Question

damien's avatar

What's a better way to ignore IE6 than using <![if !IE 6]>?

Asked by damien (2399points) July 14th, 2008

I’ve got a load of javascript which should only be run if the browser is not using IE6. Using conditional comments, I can achieve exactly this but it makes the html invalid according to w3c. Can someone suggest a better way which validates?

Observing members: 0 Composing members: 0

6 Answers

chaosrob's avatar

I don’t think there are any browser hacks that validate. Did you try Dean Edwards’ IE7 patch scripts?

Skyrail's avatar

Well if it’s JS isn’t there a way to get the browser through using JS? This long and laborious script does allow you to get browser info: http://www.quirksmode.org/js/detect.html but I’m sure a quick google will give more information :)

damien's avatar

@chaosrob, IE7 isn’t the problem with this one.. It’s just IE6 causing the headaches this time!

@Skyrail, I’ll give that a try.. I was trying to avoid needing a bulky script to check it but I guess that’s the only way forward.

Cheers for the help guys.

Skyrail's avatar

It’s okay damien, I think seeing as you’re only checking for one browser it doesn’t need to be anywhere near as bulky :) hope you get something sorted.

chaosrob's avatar

@damien Its designed to address problems in IE6, the name notwithstanding.

felipelavinz's avatar

You can use this:

<!−−[if !IE 6]−−>
<script type=“text/javascript” src=“your-script.js”></script>
<!−−<![endif]>−−>

I had to convert the dashes to ”&minus;” entities otherwise it would conver to a whisper thanks to Fluther’s markup… you should obviously use normal dashes.

Think of this as a “valid HTML” conditional comment. It works exactly as a conditional comment, but won’t break validation. There’s more on that on the MSDN documentation: About conditional comments… just check the “community content” below the article… the third or fourth comment details another way of using HTML-valid conditional comments.

Of course, there are other ways of doing this, such as with PHP and the browser agent HTTP response.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther