I am using 10.2.2 Tokyo Enterprise and FireMonkey's TWebBrowser
in an App. I wish to receive a callback response, but I don't receive a URL back when the ShouldStartLoadWithRequest
fires when I run my code.
I would like to know if this is possible without writing a wrapper. I feel I have missed something simple.
I have checked these sites and many more and have tried many different ways...
Callback from Firemonkey WebBrowser JavaScript code
Adding Javascript processing capability to TWebBrowser in iOS
Here is my simple code version:
index.html
<!DOCTYPE html><html lang="en">
<body>
<h2> Get Callback</h2>
</body>
</html>
procedure TForm2.FormCreate(Sender: TObject);
begin
WebBrowser1.URL := 'file://' + GetCurrentDir + '/../../index.html';
end;
procedure TForm2.Button1Click(Sender: TObject);
var
js : string;
begin
js := ' var url = "file://' + GetCurrentDir + '/../../index.html";'+
'var encodedurl = encodeURIComponent(url);'+
'window.location.href = encodedurl+"?67";';
WebBrowser1.EvaluateJavaScript(js);
end;
procedure TForm2.WebBrowser1ShouldStartLoadWithRequest(ASender: TObject;
const URL: string);
var
js,TheURL: String;
begin
TheURL := 'file://' + GetCurrentDir + '/../../index.html';
js := URL;
Fetch(js, TheURL+'?',true,false); //remove the URL and ?
js := TIdURI.URLDecode(js, IndyTextEncoding_UTF8);
Memo1.Lines.Text := js;
end;
Changing the end of the URL should, in principle, trick the WebBrowser into believing that it is a new URL, and I should be able to extract the number 67 while still keeping the page refreshed.
Please can you point me in the right direction?