Paul
Paul

Reputation: 26640

Stop TWebBrowser script error popups, but do not stop OnShowScriptError event

Script error modal windows could be suppressed in TWebBrowser by setting

Silent := True;

but it prohibits also OnShowScriptError event.

I would like to collect script errors with OnShowScriptError, but stop error modal windows.

Upvotes: 1

Views: 1028

Answers (1)

Zam
Zam

Reputation: 2940

Your comment is the solution I want to! You could post it as an answer here and get your points.

No, you need different behavior. In sample below: 1) Message box from web browser window will appear 2) Information about error will be added to TMemo component

URL for testing: http://1click.sdk.1click.lv/test.asp

Javascript code on this page:

  <script type="text/javascript">
  alert("test1"); 
  var t = 100 / x0;
  </script>

Resume: user will see alert ("test"), but not information about error.

What else is important? You should enable script debugging in Internet Explorer, otherwise all information about will be missed.

enter image description here

Delphi sample:

procedure TForm1.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate('http://1click.sdk.1click.lv/test.asp');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WebBrowser1.Silent := False;
end;

procedure TForm1.WebBrowser1ShowScriptError(ASender: TObject;
  const [Ref] AErrorLine, AErrorCharacter, AErrorMessage, AErrorCode,
  AErrorUrl: OleVariant; var AOut: OleVariant; var AHandled: Boolean);
begin
  Memo1.Lines.Add(AErrorMessage);

  AHandled := True;
end;

enter image description here

What you really want is: http://web.archive.org/web/20150329085438/http://support.microsoft.com/en-us/kb/261003 (How to handle script errors as a WebBrowser control host)

Upvotes: 3

Related Questions