Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Browser Detection. How to add Firefox.
Old 06-24-2007, 01:37 PM Browser Detection. How to add Firefox.
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
hi,

im using this script i foundto detect the Broswer.

(You can see it in action. here http://dansgalaxy.co.uk/ipme)

it seems to work fine in IE and opera but in firefox its showing Netscape.
i only know basic javascript commands so i have no clue on how to do this.

could someone help?

heres the code which is in the <head> tags.

Code:
<script language="JavaScript" type="text/javascript">
<!-- Original:  Gregor (legreg@legreg.de) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var useragent = navigator.userAgent;
var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;
var pos = useragent.indexOf('MSIE');
if (pos > -1) {
bVer = useragent.substring(pos + 5);
var pos = bVer.indexOf(';');
var bVer = bVer.substring(0,pos);
}
var pos = useragent.indexOf('Opera');
if (pos > -1) {
bVer = useragent.substring(pos + 6);
var pos = bVer.indexOf(' ');
var bVer = bVer.substring(0, pos);
}
if (bName == "Netscape") {
var bVer = useragent.substring(8);
var pos = bVer.indexOf(' ');
var bVer = bVer.substring(0, pos);
}
if (bName == "Netscape" && parseInt(navigator.appVersion) >= 5) {
var pos = useragent.lastIndexOf('/');
var bVer = useragent.substring(pos + 1);
}
//  End -->
</script>
and here is what is used to insert it into the page
Code:
  <tr> 
    <td>Browser Name</td>
    <td><script language="JavaScript" type="text/javascript">document.writeln('' + bName + '');</script></td>
  </tr>
  <tr> 
    <td>Browser version</td>
    <td> <script language="JavaScript" type="text/javascript">
 document.writeln('' + bVer + '');
 </script> </td>
  </tr>
i would be really greatful if someoen could show me how it can also deect ff.

Thanks,
Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 06-24-2007, 02:29 PM Re: Browser Detection. How to add Firefox.
Extreme Talker

Posts: 238
Location: United States
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
Code:
<script language="JavaScript" type="text/javascript">
<!-- Original:  Gregor (legreg@legreg.de) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var useragent = navigator.userAgent;
var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;
var pos = useragent.indexOf('MSIE');
if (pos > -1) {
bVer = useragent.substring(pos + 5);
var pos = bVer.indexOf(';');
var bVer = bVer.substring(0,pos);
}
var pos = useragent.indexOf('Opera');
if (pos > -1) {
bVer = useragent.substring(pos + 6);
var pos = bVer.indexOf(' ');
var bVer = bVer.substring(0, pos);
}
if (bName == "Netscape") {
var bVer = useragent.substring(8);
var pos = bVer.indexOf(' ');
var bVer = bVer.substring(0, pos);
}
if (bName == "Netscape" && parseInt(navigator.appVersion) >= 5) {
var pos = useragent.lastIndexOf('/');
var bVer = useragent.substring(pos + 1);
}
//  End -->
</script>
Add this to the bottom of your script, just above the // End -->
Code:
var pos = useragent.indexOf('Firefox');
if (pos > -1) {
bName = 'Firefox';
bVer = useragent.substring(pos + 6);
var pos = useragent.lastIndexOf('/');
var bVer = useragent.substring(pos + 1);
}
frost is offline
Reply With Quote
View Public Profile
 
Old 06-24-2007, 03:40 PM Re: Browser Detection. How to add Firefox.
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thanks frost!

Working fine! only noticed coz friend who uses Firefox (this was before i tested in FF) was like it says netscape thats [four letter word] Lol

nice one. i sent u some nice rep

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE

Last edited by dansgalaxy; 06-24-2007 at 03:41 PM..
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 06-24-2007, 04:12 PM Re: Browser Detection. How to add Firefox.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, you know, historicly speaking, firefox is based on the code of netscape 4, which was put in open source by netscape to create netscape 5.

So, saying that FF is seen as netscape is not that wrong...
Ok, I know, shutting up now..
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-24-2007, 04:26 PM Re: Browser Detection. How to add Firefox.
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Knowlegable.

but to be honest i dont think so i just think it showed netscape when it couldnt identify it...

but now it does.. all thanks to Frost!

i just need a good free script which can show the town/city were they are...
anyone?...
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 06-25-2007, 09:25 AM Re: Browser Detection. How to add Firefox.
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
My response to the original topic. One of the current recommendations is to use feature detection instead of browser detection. Many browsers allow for spoofing the user agent.

This is usually done by those using something other than IE on a non-windows OS. Many banking sites won't let them in unless they spoof and say its internet explorer, even though everything works just fine.

The problem is, javascript can break if Opera/Konquerr/whatever, identifies as IE and receives IE only javascript.

The other problem is, as new browsers/versions are released, detection scripts need constant updating.

By using feature detection, you can try standard DOM access first, and then attempt to downgrade to vendor specific code as needed.

As for locating a user, try geo lookup/locator. You should be able to find code for just about every server.
http://www.google.com/search?q=geo+locator
http://www.google.com/search?q=geo+lookup
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Browser Detection. How to add Firefox.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53528 seconds with 12 queries