How do I get the screen resolution of the user within a Delphi TMS Web Core Website?

79 Views Asked by At

In FMX, I could simply use the TScreen class from the FMX.Forms unit and have a function like this:

function GetScreenResolution: String;
begin
  Result := Screen.Width.ToString + 'x' + Screen.Height.ToString;
end;

But that doesn't work in TMS Web Core. I can however do the following code which is a mix between Delphi and JavaScript:

function GetScreenResolution: String;
begin
  asm
    Result = screen.width + "x" + screen.height;
  end;
end;

The above does work, but is there a better Delphi-only way instead of mixing the two languages?

1

There are 1 best solutions below

0
Shaun Roselt On BEST ANSWER

You can use window.screen from the WEB unit:

function GetScreenResolution: String;
begin
  Result := String(window.screen['width']) + 'x' + String(window.screen['height']);
end;