attachEvent

attachEvent(eventName, callback)

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

Parameters:

Name Type Description
eventName string

The event name.

callback function

Function to be called when the event fires.

Returns:

This method doesn't return any data.

Example

Copy code
builder.CreateFile("docx");
Api.attachEvent("asc_onHyperlinkClick", function() {
	console.log("HYPERLINK!!!");
});
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oRun = Api.CreateRun();
oRun.AddText("ONLYOFFICE Document Builder");
oParagraph.AddElement(oRun);
oParagraph.AddHyperlink("https://api.onlyoffice.com/docbuilder/basic", "docbuilder");
oParagraph.AddLineBreak();
oParagraph.AddText("When you click on a hyperlink from this document, the 'HYPERLINK!!!' message appears in the console log.");
builder.SaveFile("docx", "attachEvent.docx");
builder.CloseFile();

Resulting document