IOleCommandTarget
을 사용하고 IOleCommandTarget.Exec
메서드는 OLECMDID_SHOWSCRIPTERROR
명령을 사용할 수 있습니다.
다음 예제에서는 삽입 된 클래스를 사용 했으므로이 코드를 사용자의 유닛에 넣으면 폼의 웹 브라우저 또는이 유닛에서 동적으로 생성 된 웹 브라우저에서만이 동작이 발생합니다.
uses
SHDocVw, ActiveX;
type
TWebBrowser = class(SHDocVw.TWebBrowser, IOleCommandTarget)
private
function QueryStatus(CmdGroup: PGUID; cCmds: Cardinal; prgCmds: POleCmd;
CmdText: POleCmdText): HRESULT; stdcall;
function Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
const vaIn: OleVariant; var vaOut: OleVariant): HRESULT; stdcall;
end;
implementation
function TWebBrowser.QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
prgCmds: POleCmd; CmdText: POleCmdText): HRESULT; stdcall;
begin
Result := S_OK;
end;
function TWebBrowser.Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
const vaIn: OleVariant; var vaOut: OleVariant): HRESULT; stdcall;
begin
// presume that all commands can be executed; for list of available commands
// see SHDocVw.pas unit, using this event you can suppress or create custom
// events for more than just script error dialogs, there are commands like
// undo, redo, refresh, open, save, print etc. etc.
// be careful, because not all command results are meaningful, like the one
// with script error message boxes, I would expect that if you return S_OK,
// the error dialog will be displayed, but it's vice-versa
Result := S_OK;
// there's a script error in the currently executed script, so
if nCmdID = OLECMDID_SHOWSCRIPTERROR then
begin
// if you return S_FALSE, the script error dialog is shown
Result := S_FALSE;
// if you return S_OK, the script error dialog is suppressed
Result := S_OK;
end;
end;
이 방법은 또한 모든 자바 스크립트 팝업을 억제합니다. – TipTop
이런 식으로 동작하는 샘플 페이지가 있습니까? ['this'] (http://support.microsoft.com/kb/261003) 문서를 참조하십시오. 팝업이 표시되기 전에 오류가 발생하지 않았습니까? IMHO는 오류 만 표시하지 말아야합니다.하지만 ... – TLama
@TipTop, 일반적으로 코드는 자바 스크립트 호출 팝업과는 아무런 관련이 없습니다. 코드에 문제가있는 경우 기본 반환 값은 S_OK가 아니어야하지만 OLECMDERR_E_NOTSUPPORTED라고 생각합니다. – stanleyxu2005