(02-18-2020, 09:25 AM)Alexandre Machado Wrote: What are you trying to accomplish? The browser window dimensions are already set in WebApplication.FormWidth and FormHeight.
If you want to keep track if it when browser resizes, set an OnAsyncResize event handler and the information will be updated every time the browser resizes.
Unfortunately, I have already tried this and for sure it doesn't work. FormWidth and FormHeight cannot return the correct dimensions when it runs from a mobile browser like Samsung Internet. Anyway I found somewhere else the following solution:
procedure TIndex.IWAppFormCreate(Sender: TObject);
const
jsTag = '<script language="javascript" type="text/javascript">%s</script>';
var
AjaxFunc: string;
begin
AjaxFunc := 'function myAjaxFunc() {' + #13 +
'executeAjaxEvent("&data="+screen.width, null,"' + UpperCase(Self.Name) +
'.DoMyAjaxFunc", false, null, true);' + #13 +
'return true;}';
PageContext.ExtraHeader.Add(Format(jsTag, [AjaxFunc]));
WebApplication.RegisterCallBack(UpperCase(Self.Name) + '.DoMyAjaxFunc', DoMyAjaxFunc);
cmdLogin.ScriptEvents.HookEvent('OnMouseOver', 'myAjaxFunc();');
end;
procedure TIndex.DoMyAjaxFunc(EventParams: TStringList);
var
sl: TStrings;
s: string;
begin
sl := TStringList.Create;
try
sl.StrictDelimiter := True;
sl.CommaText := EventParams.Values['data'];
s := sl.CommaText;
finally
sl.Free;
end;
UserSession.MyBrowserWidth:=s2i(s);
end;

