Overview
The plugins and macros can interact with the editors using the Asc.plugin object — its events, methods, and commands. Here you will find how to use them.
- Asc.plugin — the main plugin object: properties, methods, and events
- How to attach events — listening for editor events
- How to call methods
- How to call commands
The main plugin code is placed to a .js file which describes what and how must be done by the plugin. This file is placed to the plugin root folder together with the config.json and index.html files.
How it works
Any plugin has the Asc.plugin object which provides methods and events to interact with ONLYOFFICE document, spreadsheet, presentation, and PDF editors.
Starting from version 7.1, the access to the window and document objects and the alert function is restricted from the plugin command code because the "use strict" mode was applied to the plugin scripts. Don't forget to declare variables before using them so that the plugins work correctly.
For the plugin to work the developer must specify two obligatory events for the Asc.plugin object: init and button. After that:
- callCommand is used to execute multiple Office JavaScript API commands in a single call.
- executeMethod is used to run a single editor method (e.g.
AddComment,GetSelectedText).
If the plugin operates with an OLE object, callCommand is used to manage it.
See the Asc.plugin page for a minimal working example, or the Getting started guide for a full walkthrough. More open source plugin examples can be found here.