6

I need to show text on IE only and not show it for the rest of the browsers. Any pointers to that? I looked around couldn't find it.

Fahim Akhter
  • 1,617
  • 5
  • 31
  • 49

6 Answers6

10

Conditional comments.

e.g.

<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->

(There are operators in the condition for less than, less than or equal, ... and you can chain branches to provider different behaviours for different versions see here for full details.)

Richard
  • 106,783
  • 21
  • 203
  • 265
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
2

Please note that since IE 10 conditional commenting are no longer supported and are treated as regular comments:

http://msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx

In order for it function as before you need to add the meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">

There for, for me, if I need to detect IE (although I try to avoid browser detection and use feature detection) I use some code of JS as of here:

Detect IE version (prior to v9) in JavaScript

Best.

Community
  • 1
  • 1
aviv
  • 2,719
  • 7
  • 35
  • 48
1

You have IE conditional comments or you can do it via javascript detect browser agents or with javascript frameworks such as jQuery

if (jQuery.browser.msie) {
 // do something IE specific
}
ant
  • 22,634
  • 36
  • 132
  • 182
0

Maybe in JS:

<script type="text/javascript">
    function detectBrowser(){
        var browser=navigator.appName;
        if (browser=="Microsoft Internet Explorer"){
            document.write("IE sux");
        }
    }
</script>
budzor
  • 613
  • 1
  • 6
  • 11
  • since I'm using Facebook which is pretty much a bitch so I'd have to go with the style sheet. Though this is more cooler ofcourse with the "IE sux" :D – Fahim Akhter Feb 16 '10 at 11:48
  • 3
    Please, NO. Let's stop sniffing the User Agent already, especially since IE supports conditional comments. UA is not a reliable way to find out which browser the user is running. – Piskvor left the building Feb 16 '10 at 11:50
0

The examples here presume you know javascript. It would be nice to see everything you need if you only know HTML.

e.g.

gobbledegook

  • Text I only want IE users to see.
  • moregobbledegook
    user1332994
    • 100
    • 1
    • 1
    -2

    You need to detect if current browser is IE and show content only in this case.

    The smallest script for IE detecting:

    if(-[1,]) {
       alert("Not IE!");
    }
    
    sashaeve
    • 9,387
    • 10
    • 48
    • 61