JavaScript的用户代理通过浏览器的版本号重定向 [英] javascript user agent redirect by browser version number

查看:142
本文介绍了JavaScript的用户代理通过浏览器的版本号重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有这个权利现在只有几个浏览器工作的聊天程序。所以,我插入一个用户代理重定向到管理该消息通知用户他们为​​什么不能用自己的浏览器不支持聊天。

我遇到的问题是只有Firefox 3.1及以下,例如,支持为Firefox,但低于我的自定义脚本正在使所有Firefox版本兼容。什么是只有火狐3.1兼容?解决方案

注意:我不打算把它们发送到实际的浏览器网站在我的例子中看出。我只是把这些URL为只是为了举例说明。我打算定制重定向他们与友好的消息的网页...

现有code的演示:
http://jsfiddle.net/evanmoore/4xr77/

code是如下:

 <脚本类型=文/ JavaScript的>
    如果((navigator.userAgent.indexOf('火狐')!= -1)||(navigator.userAgent.indexOf('MSIE')!= -1))
    {
        //您的浏览器支持在线聊天
        document.location =htt​​p://www.livechatinc.com/;
    }
    否则,如果(navigator.userAgent.indexOf(野生动物园)!= -1)
    {
        //你的Safari浏览器不支持在线聊天
        window.location的=htt​​p://www.apple.com;
    }
    否则,如果(navigator.userAgent.indexOf(铬)!= -1)
    {
        //你的Chrome浏览器不支持在线聊天
        window.location的=htt​​p://www.google.com/chrome;
    }
    其他
    {//所有其​​他...您的浏览器不支持在线聊天
        window.location的=htt​​p://www.gofetch.com;
    }
< / SCRIPT>


解决方案

根据阿萨德的评论,我发现不同的浏览器串的这里这让我来控制,像这样的版本号的能力......我想这应该做的伎俩!

  IF((navigator.userAgent.indexOf('火狐/ 3.1')!= -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>

解决方案

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) 

这篇关于JavaScript的用户代理通过浏览器的版本号重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆