检查浏览器功能 [英] check browser capablities

查看:174
本文介绍了检查浏览器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if ((hbc.Browser == "Firefox") && (hbc.Version<= Convert.ToString("6.0.1")))
        {
            String str1 = "<a href='http://www.firefox.com'>uspdate your browser</a>";
            Response.Write(str1);
            //Response.Write(hbc.Browser + " " + hbc.Version);
        }
        else
        {
            Response.Write(str);
            //hbc.Frames = true;
            //hbc.Capabilities["ppo"] = "http://www.google.com";
            
            //return hbc;
            Response.Write("sorry");
        }
    }




当我运行此代码时,它将显示这样的错误




when i run this code it will show an error like this

:--Operator '<=' cannot be applied to operands of type 'string' and 'string'


但是当我使用以下的insted时:-


but when i use insted of:--

hbc.Version<= Convert.ToString("6.0.1")

---hbc.Version!= "6.0.1")


它会正常运行

但我希望该版本仅检查新旧版本(如果可以使用旧版本),它将显示链接
当运行此查询时,它将仅检查我给出的该版本...
请帮我这个.....


[edit]已添加代码块,将我的内容作为纯文本..."选项已禁用-OriginalGriff [/edit]


it will run properly

but i wan that version will check is only new old version if old version is available in this it will show the link
when is run this query this will check only this version which i give...
pls help me for this.....


[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]

推荐答案

选中此选项.

Check this.

private void checkbrowser()
   {
       System.Web.HttpBrowserCapabilities hbc = Request.Browser;
       double ver = getVersion();

       if ((hbc.Browser == "Firefox") && (ver <= 6.0))
       {
           String str1 = "<a href='http://www.firefox.com'>update your browser</a>";
           Response.Write(str1);
           //Response.Write(hbc.Browser + " " + hbc.Version);
       }
       else
       {
           Response.Write("sorry");
       }
   }
   private float getVersion()
   {
       // Returns the version of Internet Explorer or a -1
       // (indicating the use of another browser).
       float rv = -1;
       System.Web.HttpBrowserCapabilities hbc = Request.Browser;
       if (hbc.Browser == "Firefox")
           rv = (float)(hbc.MajorVersion + hbc.MinorVersion);
       return rv;
   }



更多详细信息,请参见此链接
浏览器检测
MSdn



For more Details Refer this link
Browser Detection
Msdn


问题是您试图比较两个字符串以进行未定义的比较-小于或等于.它抱怨这是一件好事,因为就字符之间的比较而言,如果该版本返回的"10.1.2"小于"6.0.1",则您的测试将失败.

当您将文本替换为不等于时,可以理解地工作正常.
编写一个方法,该方法采用两个字符串参数,每个字符串参数是一个版本号,并通过在''''上拆分每个参数,然后将每个部分转换成一个数字并进行比较,来检查它是否小于或等于.这并不困难,它将为您节省很多头痛!
The problem is that you are trying to compare two strings for a comparison which is not defined - less than or equal to. And it''s a good thing it complains, because you test will fail if the version comes back with "10.1.2" which is less than "6.0.1" as far as character by character comparisons is concerned.

When you replace the text with not equal to, it understandably works fine.
Write a method which takes two string parameters, each a version number, and checks it properly for less than or equal to, by splitting each on ''.'', converting each partial into a number and comparing those. It isn''t difficult, and it will save you a lot of headache!


这篇关于检查浏览器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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