博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

判断用户浏览器类型的代码

Posted on 2007-11-15 14:33  豆丁不想长大  阅读(1263)  评论(0)    收藏  举报

public string IESupport()
    {
        string IEType = getBrower();

        ArrayList _list = new ArrayList();

        string SupportedFlashError_message = "";

        using (DBManage _db = new DBManage())
        {
            string strsql = "select SupportedFlashYesNo,SupportedFlashError_message from supported_flash where SupportedFlashID like '%" + IEType + "%'";
            if (_db.SetData(strsql, ref _list))
            {
                if (_list.Count > 0)
                {
                    string SupportedFlashYesNo = _list[0].ToString();
                    SupportedFlashError_message = _list[1].ToString();

                    if (SupportedFlashYesNo == "Yes")
                    {
                    }
                    else
                    {
                        //Response.Write("<script>alert('" + SupportedFlashError_message + "')</script>");
                        return SupportedFlashError_message;
                    }
                }
            }
        }
        return SupportedFlashError_message;
    }

    public static string getBrower()
    {
        HttpBrowserCapabilities bc = new HttpBrowserCapabilities();
        bc = HttpContext.Current.Request.Browser;
        return bc.Type;
    }
然后在前台的Body部分的Onload事件中添加js函数:
function CheckMsg()
    {
        var a = "<%=IESupport()%>";
        if(a=="")
        {
           
        }
        else
        {
          alert(a);
      }
    }