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');string
OSTypes.Add('J2ME/MIDP');
OSTypes.Add('Palm');
OSTypes.Add('BlackBerry');
OSTypes.Add('PlayStation');io
OSTypes.Add('Symbian');
OSTypes.Add('Windows Mobile');
OSTypes.Add('Windows CE');
OSTypes.Add('Windows Phone');
OSTypes.Add('PPC');
OSTypes.Add('Android');function
OSTypes.Add('Mac');
OSTypes.Add('Windows');
OSTypes.Add('Linux');List
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');vi
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;cas
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;