Introduction
The OnlyOfficeEditorModule is a JavaScript module that provides a client-side API for integrating OnlyOffice Document Server into ASP.NET applications. It acts as a wrapper around the OnlyOffice DocsAPI, providing simplified methods for initialization, document retrieval, and lifecycle management.Accessing the Module
The module is exposed as a global object and can be accessed directly from JavaScript:The OnlyOfficeEditorModule is implemented as an IIFE (Immediately Invoked Function Expression) and is available globally once the script is loaded.
Module Architecture
The module uses a singleton pattern to manage multiple editor instances:- Instance Management: Maintains internal references to all editor instances by container ID
- Event Handling: Wraps OnlyOffice events and provides custom callbacks
- Promise-based API: Modern async/await support for document operations
- Automatic Cleanup: Manages editor lifecycle and resource disposal
Prerequisites
Core Concepts
Container ID
Each editor instance is associated with a DOM container element identified by itsid attribute:
Configuration Object
The configuration object follows the OnlyOffice Document Server API structure with extensions:document: Document metadata and URLeditorConfig: Editor behavior and customizationevents: Event handlers (managed by the module)
Options Object
Custom callbacks provided by OnlyOfficeEditorModule:onReady: Called when the editor application is readyonDocumentReady: Called when the document is loadedonError: Called on errors
Available Methods
The module exposes the following public methods:| Method | Description | Returns |
|---|---|---|
init() | Initialize a new editor instance | DocEditor object |
getEditedDocumentUrl() | Get download URL for the edited document | Promise<string> |
getEditedDocumentBlob() | Get document as Blob object | Promise<Blob> |
captureToHiddenField() | Capture document to hidden field as base64 | Promise<string> |
getEditor() | Get the editor instance | DocEditor or null |
destroy() | Destroy an editor instance | void |
Quick Start Example
Browser Compatibility
The module uses modern JavaScript features:- Promises (ES6)
- Fetch API
- FileReader API
- Arrow functions (in some contexts)
Ensure your target browsers support these features or include appropriate polyfills.
Next Steps
Module Methods
Detailed documentation of all available methods
Configuration
Configuration object structure and options