简体   繁体   English

javascript 用户代理按浏览器版本号重定向

[英]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.我遇到的问题仅是 Firefox 3.1 及以下版本,例如,FireFox 支持。但我下面的自定义脚本使所有 Firefox 版本兼容。 What's the solution to have only Firefox 3.1 be compatible?只有 Firefox 3.1 兼容的解决方案是什么?

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.我只是将这些 URL 放入示例中。 I plan to have custom redirect pages with friendly messaging on them...我计划在自定义重定向页面上添加友好的消息...

Demo of existing code: http://jsfiddle.net/evanmoore/4xr77/现有代码演示: 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>

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!根据 Asad 的评论,我在这里找到了不同的浏览器字符串,这使我能够像这样控制版本号......我认为这应该可以解决问题!

if ((navigator.userAgent.indexOf('Firefox/3.1') != -1) 

Try checking if the functionality exists, not the version of the browser.尝试检查功能是否存在,而不是浏览器的版本。
eg if (typeof foo != 'undefined') will check if foo exists例如 if (typeof foo != 'undefined') 将检查 foo 是否存在
You can find more info here你可以在这里找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM