Skip to main content

attachEvent

Subscribes to the specified event and calls the callback function when the event fires.

Syntax

expression.attachEvent(eventName, callback);

expression - A variable that represents a Api class.

Parameters

NameRequired/OptionalData typeDefaultDescription
eventNameRequiredstringThe event name.
callbackRequiredfunctionFunction to be called when the event fires.

Returns

boolean

Example

Run a custom action whenever a hyperlink is clicked in a document.

// How do I run a function automatically when a hyperlink is clicked in a document?

// Listen for hyperlink clicks and trigger a response without manual intervention in a document.

Api.attachEvent("asc_onHyperlinkClick", function() {
console.log("HYPERLINK!!!");
});