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;