I want to detect a users browser type IE, Mozilla firefox, or Opera and display the correct icon next to the user name. If its not one of the three above, Display another icon.

I have this so far document writing the name of the browser, but I want the icon then username only.
no sure how to write it.please help.

<tr>
           <td class='pformstrip' colspan='2'>$active[TOTAL] 
{ibf.lang.active_users}</td>
    	</tr>
    	<tr>
          <td width="5%" class='row2'><{F_ACTIVE}></td>
          <td class='row4' width='95%'>
            <b>{$active[GUESTS]} </b> {ibf.lang.guests}, <b> $active[MEMBERS] </b> {ibf.lang.public_members} <b>$active[ANON]</b> {ibf.lang.anon_members}
            <div class='thin'>
<SCRIPT language="JavaScript"> 
<!-- 
document.write(" "
+navigator.appName+ "+{$active[NAMES]}"); 
//--> 
</SCRIPT> </div>
            {$active['links']}


        </td>
        </tr>
        <!--IBF.WHOSCHATTING-->

Have this so far, displays nicely in IE but not working in Firefox (not sure about opera or netscape)

Why is it not ok for Firefox?

<script type="text/javascript">

if ((navigator.userAgent).indexOf("Mozilla Firefox")!=-1) 
{
document.write("<img src='http://firefox.iprakash.com/images/browser_icons/firefox'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("Netscape")!=-1) 
{
document.write("<img src='http://ca.ku.ac.th/images/netscape-icon.gif'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("Opera")!=-1) 
{
document.write("<img src='http://www.dw-bg.com/img/opera_23_20.jpg'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("MSIE")!=-1) 
{
document.write("<img src='http://www.aulapublica.com/categorias/Internet%20explorer.jpg'></img> {$active[NAMES]}"); 
}
</script>

My Firefox identifies itself as:

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0

So if you remove the 'Mozilla' or the 'Firefox' from your first if condition; it works ok. To be sure; go with:

if ((navigator.userAgent).indexOf("Mozilla")!=-1 && (navigator.userAgent).indexOf("Firefox")!=-1)

That will check for the navigator string containing the word 'Mozilla' and the word 'Firefox', but not neccessarily the phrase "Mozilla Firefox".

Thankyou Again Matt! I dont know how you found time to Learn so much, but Im glad You did Mate! :D

OK it works But momentarily, After a bit It Ceases Working For Some Reason? Help?

look like this now

<script type="text/javascript">

if ((navigator.userAgent).indexOf("Mozilla")!=-1 && (navigator.userAgent).indexOf("Firefox")!=-1) 
 
{
document.write("<img src='http://firefox.iprakash.com/images/browser_icons/firefox'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("Netscape")!=-1) 
{
document.write("<img src='http://ca.ku.ac.th/images/netscape-icon.gif'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("Opera")!=-1) 
{
document.write("<img src='http://www.dw-bg.com/img/opera_23_20.jpg'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("MSIE")!=-1) 
{
document.write("<img src='http://www.aulapublica.com/categorias/Internet%20explorer.jpg'></img> {$active[NAMES]}"); 
}
</script>

Personally, I'd lose the document.write():

<html>
<head>
<script type="text/javascript">
  function showBrowserLogo()
  {
    var strBrowserId = navigator.userAgent;
    var strImage = "";
    
    alert(strBrowserId);
    
    if (strBrowserId.indexOf("Mozilla")!=-1 && strBrowserId.indexOf("Firefox")!=-1) 
    {
      strImage="http://firefox.iprakash.com/images/browser_icons/firefox";
    }
    else if (strBrowserId.indexOf("Netscape")!=-1) 
    {
      strImage="http://ca.ku.ac.th/images/netscape-icon.gif";
    }
    else if (strBrowserId.indexOf("Opera")!=-1) 
    {
      strImage="http://www.dw-bg.com/img/opera_23_20.jpg";
    }
    else if (strBrowserId.indexOf("MSIE")!=-1) 
    {
      strImage="http://www.aulapublica.com/categorias/Internet%20explorer.jpg";
    }
  
    var objImage = document.getElementById('browser_logo');
  
    objImage.src = strImage;
  
    return;
  }
</script>
</head>
<body>
<img src="" id="browser_logo"/>
<script type="text/javascript">
showBrowserLogo();
</script>
</body>
</html>

I would also try and get the 'script' section I've put within the body into the body onload event (on that example it's easy =

<body onload="showBrowserLogo();">
<img src="" id="browser_logo"/>
</body>

)

That may come out better because (most) browsers always call the onload event when a page loads or reloads, (and browsers that don't remember the JS/DOM state of pages)

ok but how to associate it with each username, so the correct icon shows for each user? eg
Inny+IE icon
Fred+Firefox icon
Wilma+ opera icon etc ???

ah.. it wont do that for you automatically. it will only be able to work out the person viewing a page's browser..

if you want to asociate forum users with their browsers... you'll have to hack your forum program.

Matt, this one, seems to do that

<script type="text/javascript">

if ((navigator.userAgent).indexOf("Mozilla")!=-1 && (navigator.userAgent).indexOf("Firefox")!=-1) 
 
{
document.write("<img src='http://firefox.iprakash.com/images/browser_icons/firefox'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("Netscape")!=-1) 
{
document.write("<img src='http://ca.ku.ac.th/images/netscape-icon.gif'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("Opera")!=-1) 
{
document.write("<img src='http://www.dw-bg.com/img/opera_23_20.jpg'></img>{$active[NAMES]}"); 
}
else if ((navigator.userAgent).indexOf("MSIE")!=-1) 
{
document.write("<img src='http://www.aulapublica.com/categorias/Internet%20explorer.jpg'></img> {$active[NAMES]}"); 
}
</script>

but stops working after a new user logs on....??

This article has been dead for over six months. Start a new discussion instead.