views:

156

answers:

5

Hello,

I have page for which I want to load different content for different browsers.

Example :

IF Internet explorer

{include file="/content1.tpl"}

ELSE if any other browser

   {include file="/content2.tpl"}

{/if}

Content1.tpl & Content 2.tpl are two different files having their respected Html & CSS.

How can I achieve this using Javascript OR php ?

Thanks,

  • Mandar

EDIT

What I want is, IE to completely neglect content2.tpl

& Mozilla or Other to completely neglect content1.tpl

+2  A: 

in PHP you could look at the superglobal named $_SERVER. There, under the HTTP_USER_AGENT key you will find the browser.

That will be computed server-side, using PHP and Smarty.

In Javascript, use this

in HTML you could use this syntax

Alexander
+4  A: 

Take a look at the get_browser() PHP function.
http://php.net/manual/en/function.get-browser.php

Note that USER AGENTS can be forged, so you can't rely on this 100%.

Rob
+10  A: 

Don't use PHP for this. You are much safer doing this at browser level, preferably using conditional comments. You cannot trust the HTTP_USER_AGENT as it is very easy for forge/change so you cannot confidently (and therefore should not) make decisions based on its value. Stick to one .tpl file and either include a specific stylesheet based on a conditional comment or add additional markup using these comments. For example you can add additional markup like this and then target accordingly:

<html>
<body>
<!--[if IE 6]><div id="ie6"><![endif]-->
... main content here
<!--[if IE 6]></div><![endif]-->
</body>
</html>
seengee
MANnDAaR
@manndaar - there is no reliable way to do that though
seengee
A: 
 <script type = " javascript" >
 if (navigator.appName == "Microsoft Internet Explorer")
{

 do this 

}else{

 do this

}
</script>

this should work, i use this all the time

TimothyTech
A: 

This Work :

<!--[if IE]>
{include file="/content1.tpl"}       
<![endif]-->

<![if !IE]>
{include file="/content2.tpl"}   
<![endif]>

Look HERE for more details.

MANnDAaR