Hi guys quick question.. having browser incompatibilities with my template in firefox so Im using a quick fix. This works for IE: <!--[If IE]>content here<![endif]--> However I dont know the browser client to make this work in chrome. If you could help out on this it would be great! Thanks, Andy
Since we only need to hack for IE, no, there is no such thing. Conditional comments are non-standard and only work in IE. If it's not working in Firefox then you coded it wrong. Whenever anyone talks of "browser incompatibilities", they almost always mean "it doesn't work in IE" and should say so. If you are using IE to first test your markup, you're doing it backwards.
While I agree with this, you could just answer his question. Chrome doesn't support 'conditionals', but you can do it with PHP. <?php $user_agent = $_SERVER['HTTP_USER_AGENT']; if ( $user_agent == strpos("$user_agent", "Chrome") ) { ?> <p>This text will ONLY appear if the user is using Chrome.</p> <?php } ?> Code (markup): Or: <?php $user_agent = $_SERVER['HTTP_USER_AGENT']; if ( $user_agent !== strpos("$user_agent", "Chrome") ) { ?> <p>This text will NOT appear if the user is using Chrome.</p> <?php } ?> Code (markup):
Except you are doing two wrong things. 1) Assuming he uses, or can use, PHP and 2) you are condoning browser sniffing, something no one should ever do. You never code to a browser. You always code to standards. And, to be clear, it's not that Chrome doesn't "support" conditionals, it's that conditionals are not standard and not supported by anything except IE which needs them to fix all it's irregularities.
I would have to agree with drhowarddrfine...always code to standard because chances are all browsers will be compatible minus IE