1

We have a chat program that works with only a couple of browsers right now. So, I'm inserting a user agent redirect to manage the messaging to inform the user why they can't chat with their unsupported browser.

The issue I'm having is only Firefox 3.1 and under, for example, is supported for FireFox., but my custom script below is enabling all Firefox versions compatible. What's the solution to have only Firefox 3.1 be compatible?

Note: I don't plan to send them to the actual browser websites as seen in my example. I just put those URLs in for example purposes only. I plan to have custom redirect pages with friendly messaging on them...

Demo of existing code: http://jsfiddle.net/evanmoore/4xr77/

Code is below:

<script type="text/javascript">
    if ((navigator.userAgent.indexOf('Firefox') != -1) || (navigator.userAgent.indexOf('MSIE') != -1)) 
    {
        // Your browser is supported for live chat
        document.location = "http://www.livechatinc.com/";
    }
    else if(navigator.userAgent.indexOf("Safari") != -1)
    {
        // Your Safari browser is not supported for live chat
        window.location = "http://www.apple.com";
    }
    else if(navigator.userAgent.indexOf("Chrome") != -1)
    {
        // Your Chrome browser is not supported for live chat
        window.location = "http://www.google.com/chrome";
    }
    else 
    {   // All others... Your browser is not supported for live chat
        window.location = "http://www.gofetch.com";
    }
</script>
Evan
  • 3,411
  • 7
  • 36
  • 53
  • 1
    Why are you redirecting people with Google Chrome and Safari to a page where they can download Google Chrome and Safari, which won't change anything? (Also, Google Chrome is usually compatible with Firefox and you should code for cross-browser chat unless you have a really good reason not to...) – Ry- Jul 16 '11 at 17:51
  • Also, Google Chrome contains the string "Safari" in its user agent so you need to move Chrome above Safari. – Ry- Jul 16 '11 at 17:52
  • @minitech It was just for the purpose of this issue. I plan to redirect them to a page that has messaging that informs them about their browser incompatibility. I don't plan on sending them to gofetch.com either. This was just an example.... Yes, our chat program is extremely limited right now. I'm aware. – Evan Jul 16 '11 at 17:54
  • 1
    Check the Firefox user agent strings [here](http://www.useragentstring.com/pages/Firefox/) and write your condition accordingly. – Asad Rasheed Jul 16 '11 at 18:02
  • @Evan: Also why don't you handle your logic with the help of server side code? I don't know your platform as you didn't mentioned it. – Asad Rasheed Jul 16 '11 at 18:04
  • @Asad - JSP. I try to stay clear from the third party's code we are hosting that way we don't introduce any compatibility issues or major changes to its functionality. I'm just trying to make modifications at the presentation layer hence the reason I did it this way. – Evan Jul 16 '11 at 18:11

2 Answers2

2

Based on Asad's comment, I found the different browser strings here which gave me the ability to control the version number like so... I think this should do the trick!

if ((navigator.userAgent.indexOf('Firefox/3.1') != -1) 
Evan
  • 3,411
  • 7
  • 36
  • 53
  • 1
    Browser detection is a bad habit from about 1995. Anyone who has the slightest clue about web development uses feature or capability detection. – RobG Jul 16 '11 at 23:49
  • @RobG At this time, our chat program is extremely limited to one browser on one operating system. while webkit and mozilla equal up to 40% of our traffic, not to mention other operating systems can't even touch the chat program, like os x, the purpose of the detection is so i can also put metrics on those custom message redirect pages and show the business how much market we are losing by people shown the incompatibility messages. this is in hope that we can get a chat program that is 100% compatible. – Evan Jul 17 '11 at 11:39
  • 1
    You can do exactly the same with feature detection - report how many incompatible browsers visit and can't use the app. Your server should be able to weed out web crawlers, bots, spiders, etc. – RobG Jul 18 '11 at 13:09
  • @RobG - Thanks Rob! I'll share this with our netadmin team who manage the server. – Evan Jul 19 '11 at 03:29
1

Try checking if the functionality exists, not the version of the browser.
e.g. if (typeof foo != 'undefined') will check if foo exists
You can find more info here

Community
  • 1
  • 1
bliof
  • 2,957
  • 2
  • 23
  • 39