User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,906 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,593 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2056 | Replies: 10
Reply
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Detect Nav Appname and display appropriate icon

  #1  
Jan 27th, 2007
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-->
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Detect Nav Appname and display appropriate icon

  #2  
Feb 2nd, 2007
PLease Assist with IF and Else Statements?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Detect Nav Appname and display appropriate icon

  #3  
Feb 5th, 2007
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>
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Detect Nav Appname and display appropriate icon

  #4  
Feb 5th, 2007
My Firefox identifies itself as:

Originally Posted by Firefox 2
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".
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Detect Nav Appname and display appropriate icon

  #5  
Feb 5th, 2007
Thankyou Again Matt! I dont know how you found time to Learn so much, but Im glad You did Mate!
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Detect Nav Appname and display appropriate icon

  #6  
Feb 10th, 2007
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>
Last edited by Inny : Feb 10th, 2007 at 12:32 am.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Detect Nav Appname and display appropriate icon

  #7  
Feb 10th, 2007
Fails after next member logs on.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Detect Nav Appname and display appropriate icon

  #8  
Feb 10th, 2007
Personally, I'd lose the document.write():

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function showBrowserLogo()
  5. {
  6. var strBrowserId = navigator.userAgent;
  7. var strImage = "";
  8.  
  9. alert(strBrowserId);
  10.  
  11. if (strBrowserId.indexOf("Mozilla")!=-1 && strBrowserId.indexOf("Firefox")!=-1)
  12. {
  13. strImage="http://firefox.iprakash.com/images/browser_icons/firefox";
  14. }
  15. else if (strBrowserId.indexOf("Netscape")!=-1)
  16. {
  17. strImage="http://ca.ku.ac.th/images/netscape-icon.gif";
  18. }
  19. else if (strBrowserId.indexOf("Opera")!=-1)
  20. {
  21. strImage="http://www.dw-bg.com/img/opera_23_20.jpg";
  22. }
  23. else if (strBrowserId.indexOf("MSIE")!=-1)
  24. {
  25. strImage="http://www.aulapublica.com/categorias/Internet%20explorer.jpg";
  26. }
  27.  
  28. var objImage = document.getElementById('browser_logo');
  29.  
  30. objImage.src = strImage;
  31.  
  32. return;
  33. }
  34. </script>
  35. </head>
  36. <body>
  37. <img src="" id="browser_logo"/>
  38. <script type="text/javascript">
  39. showBrowserLogo();
  40. </script>
  41. </body>
  42. </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)
Last edited by MattEvans : Feb 10th, 2007 at 7:28 am.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Detect Nav Appname and display appropriate icon

  #9  
Feb 10th, 2007
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 ???
Last edited by Inny : Feb 10th, 2007 at 9:39 pm.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Detect Nav Appname and display appropriate icon

  #10  
Feb 11th, 2007
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.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 7:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC