您可以从window.navigator.userAgentData.brands获取浏览器名称和版本,但这尚未在TMS Web Core中实现。window.navigator.userAgentData.brands还没有在所有浏览器中实现。 但这里有一个答案,使用window.navigator.userAgentData.brands,然后window.navigator.userAgent作为后备,以防浏览器不支持第一种方法:
uses Web;
...
function GetBrowser(IncludeVersion: Boolean): String;
var
UserAgent: String;
begin
Result := '';
asm
const userAgentData = window?.navigator?.userAgentData?.brands;
if (userAgentData !== undefined) {
Result = `${userAgentData[0].brand}`;
if (IncludeVersion === true)
Result = `${Result} (${userAgentData[0].version})`;
}
end;
if (Result = '') then
begin // Fallback in case browser doesn't have "userAgentData.brands"
UserAgent := window.navigator.userAgent;
Result := 'Unknown Browser';
if (UserAgent.indexOf('Firefox') <> -1) then Result := 'Mozilla Firefox'
else if (UserAgent.indexOf('Safari') <> -1) then Result := 'Safari'
else if (UserAgent.indexOf('Trident') <> -1) then Result := 'Internet Explorer'
else if (UserAgent.indexOf('Edg') <> -1) then Result := 'Microsoft Edge'
else if (UserAgent.indexOf('Chrome') <> -1) then Result := 'Google Chrome'
else if (UserAgent.indexOf('Vivaldi') <> -1) then Result := 'Vivaldi'
else if (UserAgent.indexOf('YaBrowser') <> -1) then Result := 'Yandex Browser'
else if (UserAgent.indexOf('OPR') <> -1) then Result := 'Opera';
if (IncludeVersion = true) then
Result := Result + ' (Unknown Version)';
end;
end;
1条答案
按热度按时间nbewdwxp1#
您可以从
window.navigator.userAgentData.brands
获取浏览器名称和版本,但这尚未在TMS Web Core中实现。window.navigator.userAgentData.brands
还没有在所有浏览器中实现。但这里有一个答案,使用
window.navigator.userAgentData.brands
,然后window.navigator.userAgent
作为后备,以防浏览器不支持第一种方法: