开发者

javascript user agent redirect by browser version number

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") 开发者_JAVA百科!= -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>


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) 


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜