« Documentation Home

opera.addEventListener()

This documentation relates to Opera's now deprecated .oex Extension API framework for Opera versions <= 12.15 and also provided by our OEX2NEX shim library.

For the latest Opera Extensions API documentation for Opera versions > 12.15 please consult the latest Opera Extensions API documentation online.

Description:

Registers a listener for an event specific to the injected script side. The listener needs to use the standard EventListener interface - a function with an Event object as its first argment, e.g. var myListener = function(event) {alert(event.type)};

Parameters:

Syntax:

void addEventListener (<DOMString> type, <EventListener> listener, useCapture)

Example:

opera.addEventListener('BeforeScript', function(userJSEvent) {
  userJSEvent.element.text = userJSEvent.element.text.replace(/function\s+window\.onload\(/g, 'window.onload = function(');
}, false);

Event types:

BeforeExternalScript

Fired when a script element with a src attribute is encountered. The script element is available in the element attribute of the UserJSEvent. If cancelled, the external source is not loaded and the script element is not executed. In addition, if it is cancelled, the BeforeScript event will not fire.

BeforeScript

Fired before a script element is executed. The script element is available in the element attribute of the UserJSEvent. The content of the script is available in the text property of the script element, and is also writable:

UserJSEvent.element.text = UserJSEvent.element.text.replace(/!=\s*null/,'');
The BeforeScript event is fired for inline scripts as well as external scripts, including scripts with a type that Opera normally does not execute (such as VBScript). If cancelled, the script element is not executed.

AfterScript

Fired after a script element has finished executing. The script element is available in the element attribute of the UserJSEvent. Modifying the text property of the event object has no effect, unlike the BeforeScript event.

BeforeEvent

Fired before a regular event is fired, regardless of whether or not an event handler has been registered for that event. The regular event is available in the event attribute of the UserJSEvent. If cancelled, the regular event is not fired, its default action is performed, and any associated BeforeEventListener events are not fired.

BeforeEvent.{type}

Like BeforeEvent, but fired only for events of the specified type (e.g., BeforeEvent.click). As shown by the example, the {type} needs to be substituted for the type of event you want to listen for. See the Event handlers on elements, Document objects, and Window objects of the HTML5 specificaton for a complete list of events. Note: at present, not all event types are supported.

AfterEvent

Fired after a regular event has been fired and handled but before its default action has been performed. The regular event is available in the event attribute of the UserJSEvent. If cancelled, any attempts by a regular event handler to cancel the regular event will be ignored. The UserJSEvent object will also have a eventCancelled property, which will be set to true if any regular event handlers have cancelled the event.

AfterEvent.{type}

Like AfterEvent, but fired only for events of the specified type (e.g., AfterEvent.click). As shown by the example, the {type} needs to be substituted for the type of event you want to listen for. See the Event handlers on elements, Document objects, and Window objects of the HTML5 specificaton for a complete list of events you can listen for. Note: at present, not all event types are supported.

BeforeEventListener

Fired before a listener for a regular event is called. The regular event is available in the event attribute of the UserJSEvent, and its regular listener is available in the listener attribute of the UserJSEvent. If cancelled, the regular event listener will not be called.

BeforeEventListener.{type}

Like BeforeEventListener, but fired only for events of the specified type (for example, BeforeEventListener.click).

AfterEventListener

Fired after a listener for regular events is called. The UserJSEvent object contains references to the original event and listener that were defined on the page. If cancelled, any attempts by a regular event handler to cancel the regular event propagation will be ignored. The UserJSEvent object will also have the propagationStopped property, which will be set to true if any regular event handlers have cancelled the event propagation.

AfterEventListener.{type}

Like AfterEventListener, but fired only for events of the specified type (for example, AfterEventListener.click). As shown by the example, the {type} needs to be substituted for the type of event you want to listen for. See the Event handlers on elements, Document objects, and Window objects of the HTML5 specificaton for a complete list of events. Note: At present, not all event types are supported.

BeforeJavascriptURL

Fired before a javascript: URL is executed. The JavaScript code to be executed (everything after the javascript: in the URL) is available in the source attribute of the UserJSEvent, and is also writable. If cancelled, the javascript: URL is not executed.

AfterJavascriptURL

Fired after a javascript: URL is executed. The JavaScript code that was executed (everything after the javascript: in the URL) is available in the source attribute of the UserJSEvent, and any value returned by that code is available in the returnValue attribute of the UserJSEvent. The returnValue is also writable. If cancelled, any returned value will not be used as the source of a new page.

pluginInitialized

Fired after a plug-in instance has been initialized. The element which represents the plug-in instance is available in the element attribute of the UserJSEvent.