fireEvent method
[This documentation is preliminary and is subject to change.]
Fires a specified event on the object.
Syntax
object.fireEvent(bstrEventName, pvarEventObject, )Standards information
There are no standards that apply here.
Parameters
- bstrEventName [in]
-
Type: BSTR
String that specifies the name of the event to fire.
- pvarEventObject [in, optional]
-
C++ Pointer to a Variant that specifies the IHTMLEventObj interface from which the event properties are obtained. JavaScript Object that specifies the event object from which to obtain event object properties. - pfCancelled [out, retval]
-
C++ Boolean that receives one of the following values: JavaScript Boolean. Returns one of the following values:
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Type: BooleanVARIANT_TRUEtrueEvent fired successfully.
VARIANT_FALSEfalseEvent was canceled.
Boolean. Returns one of the following values:Boolean that receives one of the following values:Remarks
If the event being fired cannot be canceled, fireEvent always returns VARIANT_TRUE.
Regardless of their values specified in the event object, the values of the four event properties—cancelBubble, returnValue, srcElement, and type—are automatically initialized to the values shown in the following table.
| Event object property | Value |
|---|---|
| cancelBubble | false |
| returnValue | true |
| srcElement | element on which the event is fired |
| type | name of the event that is fired |
Examples
The following sample shows how to use the fireEvent method.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/fireEventEX1.htm
<html>
<head>
<script type="text/javascript">
function fnFireEvents()
{
oDiv.innerText = "The cursor has moved over me!";
oButton.fireEvent("onclick");
}
</script>
</head>
<body>
<h1>fireEvent Method Sample</h1>
<p>By moving the cursor over the <strong>div</strong> below, the button is clicked.</p>
<div id="oDiv" onmouseover="fnFireEvents();">
Mouse over this! </div>
<p><button id="oButton" onclick="this.innerText='I have been clicked!'">Button
</button></p>
</body>
</html>
See also
- a
- abbr
- acronym
- address
- applet
- area
- b
- base
- baseFont
- bdo
- bgSound
- big
- blockQuote
- body
- br
- button
- caption
- center
- cite
- code
- col
- colGroup
- comment
- custom
- dd
- del
- dfn
- dir
- div
- dl
- dt
- em
- embed
- fieldSet
- font
- form
- frame
- frameSet
- head
- hn
- hr
- html
- i
- iframe
- img
- input type=button
- input type=checkbox
- input type=file
- input type=hidden
- input type=image
- input type=password
- input type=radio
- input type=reset
- input type=submit
- input type=text
- ins
- isIndex
- kbd
- label
- legend
- li
- link
- listing
- map
- marquee
- menu
- nextID
- noBR
- noFrames
- noScript
- object
- ol
- option
- p
- plainText
- pre
- q
- rt
- ruby
- s
- samp
- script
- select
- small
- span
- strike
- strong
- styleSheet
- sub
- sup
- table
- tBody
- td
- textArea
- tFoot
- th
- tHead
- title
- tr
- tt
- u
- ul
- var
- wbr
- xml
- xmp
- createEventObject
Build date: 3/14/2012
Following GMariani's tip, I attached fireEvent to a paragraph element and tested it against the all of the event names IE recognizes. For 59 of the event names, fireEvent returned true. For the following 20 events names, fireEvent returned the Invalid Argument error:
onabort onafterprint onbeforeprint onbeforeunload onbounce onchange onerror onfinish onhashchange onload onmessage onoffline ononline onreset onselect onselectionchange onstart onstop onsubmit onunload
When I used fireEvent to trigger onmouseover, it returned false.
- 7/19/2010
- Page Notes
I've done some test with real mouse click on an client side image map. The event object generated from my click indicates (by the window.event.srcElement property) the event is generated from <area> tag. But when I tried to programmatically call the <area>'s fireEvent(), nothing happened!
Does IE actually support simulating click on a client side image map?
- 12/13/2009
- john jst