Puede usar el IOleCommandTarget
y en su método IOleCommandTarget.Exec
tomar el comando OLECMDID_SHOWSCRIPTERROR
.
En el siguiente ejemplo, he usado la clase interpuesta así que si coloca este código en su unidad, solo aquellos navegadores web en el formulario o aquellos creados en esta unidad dinámicamente obtendrán este comportamiento.
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;
Este método también suprime todas las ventanas emergentes de JavaScript. – TipTop
¿Tiene alguna página de muestra que se comporte de esta manera? Vea el artículo ['this'] (http://support.microsoft.com/kb/261003). ¿Estás seguro de que no hay ningún error antes de que aparezca la ventana emergente? En mi humilde opinión, debería suprimir solo los errores, pero puedo echar un vistazo ... – TLama
@TipTop, en general, el código no tiene nada que ver con las ventanas emergentes que se invocan con JavaScript. Si tiene un problema con el código, creo que el valor de retorno predeterminado no debería ser S_OK, sino OLECMDERR_E_NOTSUPPORTED. – stanleyxu2005