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 detect doesn't work for firefox.
Old 06-30-2007, 06:52 PM Browser detect doesn't work for firefox.
Junior Talker

Posts: 2
Name: Micah Williamson
Trades: 0
Me and about 5 other people are making a Firefox promotion site, I already know there are others so I don't need to be told. I haven't purchased the domain yet but I do have a sponsor site that will buy it for me (photoshopsquad.com). I'm using a free hosting service to test the pages before I do anything with it- http://groogstestpages.freehostia.com/

This is what I have so far and it works pretty well except the browser detect screws up with Firefox. It says I have Netscape which I don't understand, the code I'm using in a div is-
Quote:
<script type="text/javascript">
var browser=navigator.appName
document.write("Detecting Browser... " + browser + " ")
if (browser!="Mozilla")
{
document.write("<b>You need to get Firefox!</b>")
}
</script>
Apart from the main question when I get it working will it detect the browser as "Firefox", "Mozilla" or "Mozilla Firefox"? I'm also going to want to make the border and background color change but that's a hole different topic. Any help would be appreciated!

Last edited by groog; 06-30-2007 at 06:54 PM..
groog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-04-2007, 02:01 AM Re: Browser detect doesn't work for firefox.
Extreme Talker

Posts: 238
Location: United States
Trades: 0
Try something like this:

Code:
var browser = navigator.appName;
document.write("Detecting Browser... " + browser + " ")
if (navigator.userAgent.indexOf("Firefox") == -1) {
  document.write("<b>You need to get Firefox!</b>");
}
This should be fine for your purposes, but don't be too reliant on the user agent or the navigator object, as most of the properties can be spoofed by the user or are inaccurate. (For example, Safari 3 for Windows, though beta, shows Netscape for navigator.appName.)
frost is offline
Reply With Quote
View Public Profile
 
Old 07-05-2007, 05:13 AM Re: Browser detect doesn't work for firefox.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Let me suggest that you not detect the browser for a feature. Instead, test to see if the function you want exists and then deliver an appropriate alternative if it doesn't exist. Your code will then be more forward compatible.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-05-2007, 04:03 PM Re: Browser detect doesn't work for firefox.
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by groog View Post
Apart from the main question when I get it working will it detect the browser as "Firefox", "Mozilla" or "Mozilla Firefox"?
I think this should be pretty reliable:
Code:
<script type="text/javascript">
if (!window.crypto && !GeckoActiveXObject)
{
 document.write("<b>Consider Firefox!</b>");
}
</script>

Last edited by logic ali; 07-05-2007 at 04:05 PM..
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Browser detect doesn't work for 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.25318 seconds with 12 queries