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:
, , ,

23 comments:

  1. 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... :/

    ReplyDelete
  2. 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.

    ReplyDelete
  3. 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!

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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.

    ReplyDelete
  6. 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.

    ReplyDelete
  7. 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

    ReplyDelete
  8. 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

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

    ReplyDelete
  10. custom papers

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

    ReplyDelete
  11. 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

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

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

    ReplyDelete
  14. 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!

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

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

    ReplyDelete
  17. 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

    ReplyDelete
  18. 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

    ReplyDelete
  19. Very useful information. I was very pleased. Thanks


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

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


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

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


    HTML COMMENTS

    ReplyDelete