Jump to content
Killersites Community
Andrea

Conditional Comments - What Is This?

Recommended Posts

This code is part of a navigation list I'm trying to work on (somebody else's work, very complex site)

<!--[if gte IE 7]><!--></a><!--<![endif]-->

I get the first part and the end - but what in the world is this:

<!--></a>

That is, the closing 'a' would be if the browser is IE8 or higher, then we want to close the a tag.

Why would I only want to close a link in IE8 or higher? Why not in FX, Chrome, or IE7?

 

And what could this

<!-->

possible be good for?

 

And what about the <!-- before the actual end if part? Does that have any kind of purpose, or did whoever wrote this thing simply mess up?

Share this post


Link to post
Share on other sites

conditional comments allow you to hide code from all other browsers except for IE. 

 

In this case:

gte IE 7

Means: if greater than or equal to IE7 ... display this tag. Since the code is in comments:

<!-->

.. The other browsers just ignore it.

Stef

Share this post


Link to post
Share on other sites

Oops .. disregard my posts!

 

... I should have read your whole question!

 

:unsure:

 

At first glance, it looks like messed up code. Did you run it ... does it display ok?

 

Stef

Share this post


Link to post
Share on other sites

Just finished the video :D  - you didn't talk about the mystery code, but I could confirm that I understand IE Conditional Comments.

 

Knowing where the code comes from, my first guess is that it's somebody's mess, but I didn't want to point out a mistake to find out it's actually just fancy coding.

 

It seems to work ok in IE11, but it's a huge site, and I'm not even sure if I'm looking at the right page.

 

But to sum it up - can you confirm these 2 points:

 

There is no reason to have a link close ONLY in IE7 and greater?

 

There is absolutely no point in the red stuff:

<!--[if gte IE 7]><!--></a><!--<![endif]-->

Share this post


Link to post
Share on other sites

I was too impatient to wait for a reply here, so I sent an email to our website people, saying this looks like a mistake to me, but if it's something new, I'd love an explanation, and this is the response I got:

 

I can’t explain because I didn’t set it up. Our designer researched CSS flyouts, and that’s what she found that worked with our website.

 

I just copy and tweak to fit whatever site I’m working on.

 

So there you have it, folks :raised:

Share this post


Link to post
Share on other sites

If my memory serves me correctly, I think that code came from Stu at cssplay.com where flyouts didn't work for IE7 or earlier unless that comment was in there. I know it's weird but it did work and without it just broke.  Of course that flyout example is long gone but I bet if I dug through all my old codes I could find it.

Share this post


Link to post
Share on other sites

Thanks Eddie, no need to waste time. Still makes no sense to me, so.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×