K
K
KzLIFE2014-10-18 05:54:21
JavaScript
KzLIFE, 2014-10-18 05:54:21

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>

it is necessary that when you click on the link in the browser, the procedure test will work
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

1 answer(s)
B
Be Joy, 2014-10-18
@bejoy

// * Отлавливаем в 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 question

Ask a Question

731 491 924 answers to any question