January 01, 2008

Conditional statements in html code

HAPPY NEW YEAR!

2008 is here and I am confident it will be a very good year. My first post this year is no breaking news. Still good to know.

When creating web sites it always comes up browser specific issues where Internet explorer and Firefox don't render the code equally. So annoying... However using css and/or conditional statements in the html code it is possible to launch different html blocks depending on if the browser is Internet explorer or not.

The HTML will run if the browser is Internet explorer:
<!--[If IE]>
HTML
<![endif]-->

The HTML will run if the browser is NOT Internet explorer:
<!--[if !IE]>-->
HTML
<!--<![endif]-->


W3schools has an excellent css reference and this blog post explains and shows examples on conditional statements.



Technorati tags:
, , ,


26 comments:

Greven said...

Neat, it was actually 'news' to me!

But maybe it's even bigger news that we STILL in the year 2008 have to care about that crap at all... :/

Niklas Waller said...

I totally agree! Why can't we all just agree on some standards! I just found out that when I made it work (using this technique) on firefox and IE on Windows it does not look the same for Safari and Firefox on Mac.... So I guess to make it more foolproof some Javascript is needed to check for OS and browser to try to cover most possibilities. Still not foolproof and a lot of booring work.

However these conditional statements can be used succesfully many times though depending on what you do.

Phil said...

Hi Nick,

Thanks for the link! Conditional comments are the best way to fix discrepancies in standards support between IE and the rest, in my opinion.

Sorry to hear you are having problems with the Mac browsers though. I normally don't get a difference as both versions of Firefox and Safari are pretty good at support of the standards. In that case I would look into your current code before looking to JavaScript browser sniffing. If you need someone else to look over it and see what may be causing Safari to choke on something that Firefox for Windows doesn't, I'd be happy to!

Niklas Waller said...

Hi Phil,
You're welcome, it was a good post that helped me a great deal.

I appreciate your offer.
I am having troubles on a site with the length of input text fields and lengths of some table cells. The strange thing is that it actually differs between Safari and Firefox on Mac. I am able to control the difference on windows using the conditional comments but it's more difficult on mac for me since I don't have one ;-)

I will post a question on your blog later on when I have more time. I might also throw in a question on css positioning that is bothering me for floating divs if I don't find a solution.

/ Nick

Babor said...

Hi Nick,

Thanks for the code. I was looking for this type of code. I dont know the bug of the Conditional HTML for Browsers but seems it is working for me.

gfh said...

Our website are the reliable wow gold and wow power leveling wow gold

Bobby said...

I am trying to make some script tags run in all browsers except iPhone and iPod Touch. Does anyone know what the string is for that? I tried MobileSaf and it did not work.

Ben said...

Thanks for great tips!
Custom web design companies

James said...

Neat, it was really 'news' to me!

But maybe it's even larger than the information that we STILL in the year 2008 must be interested in all that crap ... Thesis AND Dissertation AND Essay AND Assignment

Paul said...

Conditional comments are the best way to fix discrepancies in standards support between IE and the rest, in my opinion.Thanks for the link! sword & knives Accessories and Things Link Building Services Herbal Products Social Bookmarking Submission Blog Posting Service

pariuri sportive said...

Great Article!Thanks for sharing this information. I got a chance to know about this.

custom papers said...

custom papers

This is really good and interesting piece of work. i liked it,and wanted to know more about it.

Andy said...

its 2010 now and browser compatibility is no longer a problem. IE6 has been retired and chrome is taking over Firefox.

-faraz from blu ray ripper software and best blu ray software

Web 2.0 Design said...

Excellent post. Thanks a bunch for sharing this....
Website Design Company

Die Denker said...

Thanks for the tip! It allowed us to apply something that didn't work in IE.

Nursing assistant classes said...

I love your blog so much, and there are just some differences with others'. Hope there will be more wonderful things in your blog. Happy every day!

ipad 3 said...

Thanks for the information, I really appreciated the read.keep it up.

dekorasyon said...

its 2010 now and browser compatibility is no longer a problem. IE6 has been retired and chrome is taking over Firefox.

tadilat said...

Phone ve iPod Touch dışındaki tüm tarayıcılarda çalışan bazı script etiketleri yapmaya çalışıyorum. Herkes dize bu ne için olduğunu biliyor mu? Ben MobileSaf denedim ve işe yaramadı.boyaci
boya
dekorasyon
çati

Nepal Trekking said...

Responsible Travel Company in Nepal. Organizing Nepal Trekking, Travel, Ticketing, Trekking Nepal Information Portal and also promotes Mount Kailash Tours and India Tours.
For more details log on: http://www.samratnepal.com

cati tamiri said...

I just found out that when I made it work (using this technique) on firefox and IE on Windows it does not look the same for Safari and Firefox on Mac.... So I guess to make it more foolproof some Javascript is needed to check for OS and browser to try to cover most possibilities.
cati tamiri
cati izolasyonu

cati izolasyon said...

Very useful information. I was very pleased. Thanks


küp taş said...

You're welcome, it was a good post that helped me a great deal.

küptaş
Granit
DoğalTaş
Bazalt
Küp Taş Ustası


boyacı said...

Thanks for the link! Conditional comments are the best way to fix discrepancies in standards support between IE and the rest, in my opinion.

Tedos said...

I can suggest my own personal point of view on this problem or buy online essay at this service prepared for my college mates. In general, great deal of meaning of all scientific data that are gathered in it come from social studies, historical facts and general surveys. But there are things that keep being an open question for me as well as for any educated man or woman in united states.

Suresh Kumar said...

http://allinworld99.blogspot.in/2014/08/html-comment.html


HTML COMMENTS