Compartilhar via


initEvent method

Initializes a new generic event that the IDocumentEvent::createEvent method created.

 

Syntax

HRESULT retVal = object.initEvent(eventType, canBubble, cancelable);

Parameters

eventType [in]

Type: BSTR

The event IDOMEvent::type.

canBubble [in]

Type: VARIANT_BOOL

VARIANT_TRUE (true)

The event should propagate upward.

VARIANT_FALSE (false)

The event does not propagate upward.

cancelable [in]

Type: VARIANT_BOOL

VARIANT_TRUE (true)

The default action can be canceled.

VARIANT_FALSE (false)

The default action cannot be canceled.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information

Remarks

You can call the IDOMEvent::initEvent method only before the IEventTarget::dispatchEvent method dispatches the event object. After the event is dispatched, its properties cannot be changed.

Examples

The following code example creates a custom event that bubbles but cannot be canceled.

var evt = document.createEvent("Event");
evt.initEvent("custom", true, false);
document.getElementById('target').dispatchEvent(evt); 

See also

Reference

IDOMEvent::bubbles

IDOMEvent::cancelable

IEventTarget::dispatchEvent