如何截获IE中的form submit事件?(50分)

  • 主题发起人 主题发起人 carolson2
  • 开始时间 开始时间
C

carolson2

Unregistered / Unconfirmed
GUEST, unregistred user!
比如 IE 的html中有有个form
点提交 这个事件。

actionsaveexecute ?
 
先得到这个form的IHTMLFormElement接口,他里面有onsubmit事件。
// *********************************************************************//
// Interface: IHTMLFormElement
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {3050F1F7-98B5-11CF-BB82-00AA00BDCE0B}
// *********************************************************************//
IHTMLFormElement = interface(IDispatch)
['{3050F1F7-98B5-11CF-BB82-00AA00BDCE0B}']
procedure Set_action(const p: WideString); safecall;
function Get_action: WideString; safecall;
procedure Set_dir(const p: WideString); safecall;
function Get_dir: WideString; safecall;
procedure Set_encoding(const p: WideString); safecall;
function Get_encoding: WideString; safecall;
procedure Set_method(const p: WideString); safecall;
function Get_method: WideString; safecall;
function Get_elements: IDispatch; safecall;
procedure Set_target(const p: WideString); safecall;
function Get_target: WideString; safecall;
procedure Set_name(const p: WideString); safecall;
function Get_name: WideString; safecall;
procedure Set_onsubmit(p: OleVariant); safecall;
function Get_onsubmit: OleVariant; safecall;
procedure Set_onreset(p: OleVariant); safecall;
function Get_onreset: OleVariant; safecall;
procedure submit; safecall;
procedure reset; safecall;
procedure Set_length(p: Integer); safecall;
function Get_length: Integer; safecall;
function Get__newEnum: IUnknown; safecall;
function item(name: OleVariant; index: OleVariant): IDispatch; safecall;
function tags(tagName: OleVariant): IDispatch; safecall;
property action: WideString read Get_action write Set_action;
property dir: WideString read Get_dir write Set_dir;
property encoding: WideString read Get_encoding write Set_encoding;
property method: WideString read Get_method write Set_method;
property elements: IDispatch read Get_elements;
property target: WideString read Get_target write Set_target;
property name: WideString read Get_name write Set_name;
property onsubmit: OleVariant read Get_onsubmit write Set_onsubmit;
property onreset: OleVariant read Get_onreset write Set_onreset;
property length: Integer read Get_length write Set_length;
property _newEnum: IUnknown read Get__newEnum;
end;
 
谢谢。但是还是不是很明确。如果有现成的稍微详细的,或者是类似的代码就好了。

偶自己到是用了HTMLElement 但是 老是崩溃。
 
连接到这个接口当提交时就会发个消息通知你
HTMLFormElementEvents = dispinterface
['{3050F364-98B5-11CF-BB82-00AA00BDCE0B}']
function onhelp: WordBool; dispid -2147418102;
function onclick: WordBool; dispid -600;
function ondblclick: WordBool; dispid -601;
function onkeypress: WordBool; dispid -603;
procedure onkeydown; dispid -602;
procedure onkeyup; dispid -604;
procedure onmouseout; dispid -2147418103;
procedure onmouseover; dispid -2147418104;
procedure onmousemove; dispid -606;
procedure onmousedown; dispid -605;
procedure onmouseup; dispid -607;
function onselectstart: WordBool; dispid -2147418100;
procedure onfilterchange; dispid -2147418095;
function ondragstart: WordBool; dispid -2147418101;
function onbeforeupdate: WordBool; dispid -2147418108;
procedure onafterupdate; dispid -2147418107;
function onerrorupdate: WordBool; dispid -2147418099;
function onrowexit: WordBool; dispid -2147418106;
procedure onrowenter; dispid -2147418105;
procedure ondatasetchanged; dispid -2147418098;
procedure ondataavailable; dispid -2147418097;
procedure ondatasetcomplete; dispid -2147418096;
procedure onlosecapture; dispid -2147418094;
procedure onpropertychange; dispid -2147418093;
procedure onscroll; dispid 1014;
procedure onfocus; dispid -2147418111;
procedure onblur; dispid -2147418112;
procedure onresize; dispid 1016;
function ondrag: WordBool; dispid -2147418092;
procedure ondragend; dispid -2147418091;
function ondragenter: WordBool; dispid -2147418090;
function ondragover: WordBool; dispid -2147418089;
procedure ondragleave; dispid -2147418088;
function ondrop: WordBool; dispid -2147418087;
function onbeforecut: WordBool; dispid -2147418083;
function oncut: WordBool; dispid -2147418086;
function onbeforecopy: WordBool; dispid -2147418082;
function oncopy: WordBool; dispid -2147418085;
function onbeforepaste: WordBool; dispid -2147418081;
function onpaste: WordBool; dispid -2147418084;
function oncontextmenu: WordBool; dispid 1023;
procedure onrowsdelete; dispid -2147418080;
procedure onrowsinserted; dispid -2147418079;
procedure oncellchange; dispid -2147418078;
procedure onreadystatechange; dispid -609;
procedure onbeforeeditfocus; dispid 1027;
function onsubmit: WordBool; dispid 1007;
function onreset: WordBool; dispid 1015;
end;

对于ONSUBMIT事件,MSDN是这么说的
HTMLFormElementEvents::onsubmit Event

--------------------------------------------------------------------------------

Fires when a FORM is about to be submitted.

Syntax

VARIANT_BOOL onsubmit( VOID);
Return Value

If the event bubbles and is cancellable, return VARIANT_TRUE to prevent the event from bubbling to other event handlers in the document tree. Return VARIANT_FALSE to allow bubbling.

Event DISPID

DISPID_HTMLFORMELEMENTEVENTS_ONSUBMIT
The DISPID for this event is defined in mshtmdid.h. Use this value to identify the event handler when implementing IDispatch::Invoke.

Event Information

Bubbles No
Cancels Yes
To invoke Submit a form using the INPUT TYPE=submit, INPUT TYPE=image, or BUTTON TYPE=submit object.
Default action Causes a form to be sent to whatever location is stipulated in the ACTION attribute of the form object.

Event Object Properties

When the onsubmit event is fired, you can query for any of the following properties on the IHTMLEventObj, IHTMLEventObj2, or IHTMLEventObj3 interfaces. Use the IHTMLWindow2::event property on the IHTMLWindow2 interface to retrieve the IHTMLEventObj interface for the current event. Alternatively, for the HTMLXxxEvents2 interfaces, you can use the pEvtObj parameter to access the current event object. To obtain an IHTMLEventObj2 or IHTMLEventObj3 interface pointer, call QueryInterface on the IHTMLEventObj interface.

Hide Available Properties

IHTMLEventObj::altKey Retrieves a value that indicates the state of the ALT key.
IHTMLEventObj2::altKey Sets or retrieves a value that indicates the state of the ALT key.
IHTMLEventObj3::altLeft Sets or retrieves a value that indicates the state of the left ALT key.
IHTMLEventObj::ctrlKey Retrieves the state of the CTRL key.
IHTMLEventObj2::ctrlKey Sets or retrieves the state of the CTRL key.
IHTMLEventObj3::ctrlLeft Sets or retrieves the state of the left CTRL key.
IHTMLEventObj::returnValue Sets or retrieves the return value from the event.
IHTMLEventObj::shiftKey Retrieves the state of the SHIFT key.
IHTMLEventObj2::shiftKey Sets or retrieves the state of the SHIFT key.
IHTMLEventObj3::shiftLeft Retrieves the state of the left SHIFT key.
IHTMLEventObj::srcElement Retrieves the object that fired the event.
IHTMLEventObj2::srcElement Sets or retrieves the object that fired the event.
IHTMLEventObj::type Sets or retrieves the event name from the event object.
IHTMLEventObj2::type Sets or retrieves the event name from the event object.

Remarks

You can override this event by returning false in the event handler. Use this capability to validate data on the client side to prevent invalid data from being submitted to the server. If the event handler is called by the HTMLFormElementEvents::onsubmit attribute of the form object, the code must explicitly request the return value using the return function, and the event handler must provide an explicit return value for each possible code path in the event handler function.

The IHTMLFormElement::submit method does not invoke the HTMLFormElementEvents::onsubmit event handler.

See Also

ACTION, METHOD
 
后退
顶部