Answer the question
In order to leave comments, you need to log in
How to call a Delphi procedure from Javascript (external.test)?
The form has a WebBrowser component in the browser page index.html
<html>
<body>
<a href="external.test()">Вызовы тестовой процедуры</a>
</body>
</html>
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, MSHTML, StdCtrls, Buttons;
type
TForm1 = class(TForm)
internet: TWebBrowser;
BitBtn1: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
internet.Navigate('file://' + GetCurrentDir + '/html/index.html');
end;
procedure test;
begin
ShowMessage('123');
end;
end.
Answer the question
In order to leave comments, you need to log in
// * Отлавливаем в browser переход по ссылке
procedure TForm1.WeberBeforeNavigate2(ASender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
var
S: String;
begin
// * Получаем ссылку
S := URL;
// * Сравниваем ссылку с условием
if ( S[1] = 'external.test()' ) then
begin
// * Отменяем переход по ссылке
Cancel := True;
// * Вызываем процедуру
test;
end
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question