tags:

views:

96

answers:

4

Hi,

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.

+8  A: 

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

David Dorward
This answer would be even better with an example code snippet.
deceze
why bother there is snippet on the hyperlink he provided
c0mrade
Expanded it... and include link to MSDN for the full details.
Richard
So I just put <p> THIS IS IE </p> in the conditional comments?
Fahim Akhter
@Fahim Akhter: Exactly.
Piskvor
Here is my code: <!--[if lt IE 8]> <p>This game may not display properly on ancient Browsers (IE 6 or lower) please upgrade so you can play the game</p> <![endif]-->http://apps.facebook.com/feline-frenzy/which does not seem to be working
Fahim Akhter
Apparently Conditional Comments are not working in Facebook :/
Fahim Akhter
Doesn't FaceBook have two modes? "You can't write HTML here" and "This is your (application) page loaded in an iframe, everything inside it works as normal"? I don't see why either of those would fail.
David Dorward
+1  A: 

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
}
c0mrade
A: 

Maybe in JS:

<script type="text/javascript">
    function detectBrowser(){
        var browser=navigator.appName;
        if (browser=="Microsoft Internet Explorer"){
            document.write("IE sux");
        }
    }
</script>
budzor
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
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
ok, my bad. sry
budzor
A: 

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
A Javascript bug hack?! Ouch! I hope nobody will actually use this.
deceze
I also hope :) But I think it is an interesting script as it's being the smallest one on this moment for IE detecting.
sashaeve