•
•
•
•
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
![]() |
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.
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
W. C. Fields
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?
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
W. C. Fields
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation:
Rep Power: 5
Solved Threads: 47
My Firefox identifies itself as:
So if you remove the 'Mozilla' or the 'Firefox' from your first if condition; it works ok. To be sure; go with:
That will check for the navigator string containing the word 'Mozilla' and the word 'Firefox', but not neccessarily the phrase "Mozilla Firefox".
•
•
•
•
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.
OK it works But momentarily, After a bit It Ceases Working For Some Reason? Help?
look like this now
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
W. C. Fields
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation:
Rep Power: 5
Solved Threads: 47
Personally, I'd lose the document.write():
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 =
)
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)
Javascript Syntax (Toggle Plain Text)
<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)
Last edited by MattEvans : Feb 10th, 2007 at 7:28 am.
If it only works in Internet Explorer; it doesn't work.
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 ???
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
W. C. Fields
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Previous Thread: can anyone make this tree table sort correctly?
- Next Thread: I hate Firefox!


Linear Mode