Jump to content

Javascript question


lema

Recommended Posts

Hi to all.

 

How can I get into a Delphi variable the result of a JavaScript function like getTimezoneOffset() ?

 

I can successfully execute the following and get the result on caption of UniLabel1

 UniSession.AddJS(
   'var d = new Date(); ' +
   'var _offset = (d.getTimezoneOffset() / 60 ) * -1; ' +
   'TestForm.UniLabel1.setText(_offset); '
   );

 

 

Regards.

Link to comment
Share on other sites

  • Administrators

It can be done using an Ajax request:

 

  UniSession.AddJS(
'var d = new Date(); ' +
'var _offset = (d.getTimezoneOffset() / 60 ) * -1; ' +
'ajaxRequest(MainForm.form, "mycall", ["ofs="+_offset]); '
);

 

 

procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string;
 Params: TStrings);
begin
 if EventName='mycall' then
 begin
UniLabel1.Caption:=Params.Values['ofs'];
 end;
end;

  • Upvote 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...