Jump to content

How To Get The Browser Name And Version Number?


Frederick

Recommended Posts

I am using the following code to try to get the browser name but all I am getting is "Others". It is the same whether I run in Firefox, Chrome, Edge or Opera.

var
   ClientInfo : TUniClientInfos;
begin
   ClientInfo:=UniApplication.ClientInfo;
   if ciIE in ClientInfo then
      Result := 'IE'
   else if (ciFireFox in ClientInfo) or (ciFirefox2 in ClientInfo) or (ciFirefox3 in ClientInfo) then
      Result := 'FireFox'
   else if ciOpera in ClientInfo then
      Result := 'Opera'
   else if ciSafari in ClientInfo then
      Result := 'Safari'
   else if ciChrome in ClientInfo then
      Result := 'Chrome'
   else
      Result  := 'Other';
end;

Additionally, how do I detect the Microsoft Edge browser and the version number of any browser?

--
Frederick
(UniGUI Complete - Professional Edition 1.90.0.1549)
 

Link to comment
Share on other sites

46 minutes ago, Frederick said:

Additionally, how do I detect the Microsoft Edge browser and the version number of any browser?

Hello,

You can improve a little with this function:

function getBrowserName(AUserAgent: string): string;
function TMainForm.getBrowserName(AUserAgent: string): string;
begin
  if AUserAgent = '' then
  begin
    Result := '';
    Exit;
  end;

  AUserAgent := LowerCase(AUserAgent);

  if Pos('edge', AUserAgent) > 0 then Result := 'edge'
  else if Pos('edg', AUserAgent) > 0 then Result := 'chromium based edge (dev or canary)'
  else if Pos('opr', AUserAgent) > 0 then Result := 'opera'
  else if Pos('chrome', AUserAgent) > 0 then Result := 'chrome'
  else if Pos('trident', AUserAgent) > 0 then Result := 'ie'
  else if Pos('firefox', AUserAgent) > 0 then Result := 'firefox'
  else if Pos('safari', AUserAgent) > 0 then Result := 'safari'
  else Result := 'other';
end;

Usage:

procedure TMainForm.UniFormActivate(Sender: TObject);
var
  C : TUniClientInfoRec;
  userAgent: string;
begin
  UniLabel7.Caption:=UniApplication.RemoteAddress;

  C:=UniApplication.ClientInfoRec;

  UniLabel6.Caption:=C.BrowserType;
  UniLabel4.Caption:=IntToStr(C.BrowserVersion);
  UniLabel5.Caption:=C.OSType;

  UniLabel9.Text := getBrowserName(UniSession.UserAgent); //<-----

end;

https://social.msdn.microsoft.com/Forums/en-US/edde0150-9478-4ca6-ba0f-9e084b5a4719/how-to-detect-microsoft-edge-chromium-chrome-ie-browser-using-javascript?forum=iewebdevelopment

Link to comment
Share on other sites

Thanks. The GetBrowserName() function gives me the information I need.

However, the BrowserType, OSType and BrowserVersion properties from UniApplication.ClientInfoRec do not return anything of value since the first two are blank strings and the third is a 0 regardless of the browser I run the app with.

Link to comment
Share on other sites

On 5/5/2021 at 3:40 PM, Frederick said:

Thanks. The GetBrowserName() function gives me the information I need.

However, the BrowserType, OSType and BrowserVersion properties from UniApplication.ClientInfoRec do not return anything of value since the first two are blank strings and the third is a 0 regardless of the browser I run the app with.

+1

Link to comment
Share on other sites

  • 1 month later...

how to get data in mobile?

fWebBrowser is 0 (empty)

procedure TUniMainModule.GetBrowserType;
Var
 cir: TUniClientInfoRec;
begin
  cir := UniSession.UniApplication.ClientInfoRec;
  fWebBrowser := cir.BrowserType + ' ' + cir.BrowserVersion.ToString;
end;

 

UniSession.UniApplication.ClientInfoRec is empty :(

Link to comment
Share on other sites

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...