Hi,
The answer is probably simple, but this does not work. What does?:
Function WebBrowserJSGetTitle(AAdvWebBrowser:TadvWebbrowser):string;
var Atitle:string;
begin
Atitle:='WebBrowserGetTitle nu nog uitwerken';
AAdvWebBrowser.ExecuteJavascript('function GetHTML(){return unescape(document.title);} GetHTML();',
procedure(const AValue: string)
begin
Atitle:= AValue;
end
);
result:=Atitle;
end;
The ExecuteJavaScript callback is asychronous, so the ATitle parameter will be empty as a result. You need to await the callback and then the ATitle value will be set. You can not use the value as a result in a function, you'll need to call an event when the callback is triggered.
Hi Pieter,
Could you tell how that has to be done? I could not find an example of this: the manual is quit brief on it.
Thanks
The code you have used is correct, you just need to call your method or function from within the callback:
procedure WebBrowserJSGetTitle(AAdvWebBrowser:TadvWebbrowser);
var
ATitle: string;
begin
AAdvWebBrowser.ExecuteJavascript('function GetHTML(){return unescape(document.title);}GetHTML();',
procedure(const AValue: string)
begin
ATitle:= AValue;
//callmethod or function
end);
end;