• unigui判断浏览器内核、操作系统以及是否移动终端函数


    function GetDeviceType(var OsName, BrowserName: string; var IsMobileDevice: Boolean): string;
    var
      I: Integer;
      BrowserInfo: string;
      OSTypes, BrowserTypes: TStringList;
    begin
      Result := '';
    
      BrowserName := 'Unknown';
      OsName := 'Unknown';
      IsMobileDevice := False;
    
      BrowserInfo := UniApplication.UniSession.RequestHeader['User-Agent'];
      OSTypes := TStringList.Create;
      BrowserTypes := TStringList.Create;
      try
        OSTypes.Add('Ipod');
        OSTypes.Add('Ipad');
        OSTypes.Add('Iphone');
    
        OSTypes.Add('J2ME/MIDP');
        OSTypes.Add('Palm');
        OSTypes.Add('BlackBerry');
        OSTypes.Add('PlayStation');
    
        OSTypes.Add('Symbian');
        OSTypes.Add('Windows Mobile');
        OSTypes.Add('Windows CE');
        OSTypes.Add('Windows Phone');
        OSTypes.Add('PPC');
        OSTypes.Add('Android');
    
        OSTypes.Add('Mac');
        OSTypes.Add('Windows');
        OSTypes.Add('Linux');
    
        OSTypes.Add('Unknown');
    
        //微软IE
        BrowserTypes.Add('MSIE 5.5');
        BrowserTypes.Add('MSIE 6.5');
        BrowserTypes.Add('MSIE 7.0');
        BrowserTypes.Add('MSIE 8.0');
        BrowserTypes.Add('MSIE 9.0');
        BrowserTypes.Add('MSIE 10.0');
        BrowserTypes.Add('MSIE 11.0');
        BrowserTypes.Add('MSIE');
    
        BrowserTypes.Add('Netscape'); //网景
        BrowserTypes.Add('Firefox'); //火狐
        BrowserTypes.Add('Chrome'); //谷歌
        BrowserTypes.Add('Safari');
        BrowserTypes.Add('Opera');
    
        for I := 0 to BrowserTypes.Count - 1 do
        begin
          if Pos(Uppcase(BrowserTypes[I]), Uppcase(BrowserInfo)) <> 0 then
          begin
            BrowserName := BrowserTypes[I];
            Break;
          end;
        end;
    
        for I := 0 to OSTypes.Count - 1 do
        begin
          if Pos(Uppcase(OSTypes[I]), Uppcase(BrowserInfo)) <> 0 then
          begin
            OsName := OSTypes[I];
            Break;
          end;
        end;
    
        IsMobileDevice := OSTypes.IndexOf(OsName) <= OSTypes.IndexOf('Android');
      finally
        FreeAndNil(OSTypes);
        FreeAndNil(BrowserTypes);
      end;
    end;
    
    
      //使用方法
      GetDeviceType(OsName, BrowserName, IsMobileDevice);
      ShowMessage('操作系统类型:' + OsName);
      ShowMessage('浏览器内核:' + BrowserName);
    
      if IsMobileDevice then
        ShowMessage('移动设备')
      else
        ShowMessage('非移动设备');
    
      //显示IE浏览器使用
      if Pos('MSIE',BrowserName) <> 0 Then
      begin
        ShowMessage('本系统暂不支持微软IE内核浏览器,推荐使用基于谷歌Chrome内核的浏览器!');
        Close;
      end;
    
  • 相关阅读:
    BZOJ-1497 最大获利
    POJ-3680 Intervals & NOI 2008 志愿者招募 费用流
    CodeForces 663E Binary Table
    南昌区域赛-G Eating Plan
    HDU-5909 Tree Cutting
    BZOJ-4589 Hard Nim
    UVA-12633 Super Rooks on Chessboard
    SPOJ-TSUM Triple Sums
    HDU-4609 3-idiots
    Kattis-aplusb A+B problem
  • 原文地址:https://www.cnblogs.com/findumars/p/4209627.html
Copyright © 2020-2023  润新知