Events

The events section allows to change all the functions pertaining to the events.

  • onAppReady - the application is loaded into the browser.
  • onCollaborativeChanges - the document is co-edited by the other user in the strict co-editing mode.
  • onDocumentReady - the document is loaded into the document editor.
  • onDocumentStateChange - the document is modified.
  • onDownloadAs - the absolute URL to the edited file when the downloadAs method is being called.
  • onError - an error or some other specific event occurs.
  • onInfo - the application opened the file.
  • onMetaChange - the meta information of the document is changed via the meta command.
  • onMakeActionLink - the user is trying to get link for opening the document which contains a bookmark, scrolling to the bookmark position.
  • onOutdatedVersion - the document is opened for editing with the old document.key value, which was used to edit the previous document version and was successfully saved.
  • onPluginsReady - all plugins are loaded and can be used.
  • onReady - the application is loaded into the browser.
  • onRequestClose - the work with the editor must be ended and the editor must be closed.
  • onRequestCompareFile - the user is trying to select document for comparing by clicking the Document from Storage button.
  • onRequestCreateNew - the user is trying to create document by clicking the Create New button.
  • onRequestEditRights - the user is trying to switch the document from the viewing into the editing mode by clicking the Edit Document button.
  • onRequestHistory - the user is trying to show the document version history by clicking the Version History button.
  • onRequestHistoryClose - the user is trying to go back to the document from viewing the document version history by clicking the Close History button.
  • onRequestHistoryData - the user is trying to click the specific document version in the document version history.
  • onRequestInsertImage - the user is trying to insert an image by clicking the Image from Storage button.
  • onRequestMailMergeRecipients - the user is trying to select recipients data by clicking the Mail merge button.
  • onRequestReferenceData - the user is trying to refresh data inserted from the external file by clicking the Update values button in the External links dialog box of the Data tab.
  • onRequestRename - the user is trying to rename the file by clicking the Rename… button.
  • onRequestRestore - the user is trying to restore the file version by clicking the Restore button in the version history.
  • onRequestSaveAs - the user is trying to save file by clicking Save Copy as… button.
  • onRequestSendNotify - the user is mentioned in a comment.
  • onRequestSharingSettings - the user is trying to manage document access rights by clicking Change access rights button.
  • onRequestUsers - the commenter can select other users for mention in the comments.
  • onWarning - a warning occurs.

Events and their description:

  • onAppReady - the function called when the application is loaded into the browser.

    Example

    1. var onAppReady = function () {
    2. console.log("ONLYOFFICE Document Editor is ready");
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onAppReady": onAppReady,
    7. ...
    8. },
    9. ...
    10. });
  • onCollaborativeChanges - the function called when the document is co-edited by the other user in the strict co-editing mode.

    Example

    1. var onCollaborativeChanges = function () {
    2. console.log("The document changed by collaborative user");
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onCollaborativeChanges": onCollaborativeChanges,
    7. ...
    8. },
    9. ...
    10. });
  • onDocumentReady - the function called when the document is loaded into the document editor.

    Example

    1. var onDocumentReady = function () {
    2. console.log("Document is loaded");
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onDocumentReady": onDocumentReady,
    7. ...
    8. },
    9. ...
    10. });
  • onDocumentStateChange - the function called when the document is modified. It is called with the parameter: {“data”: true} when the current user is editing the document and with the parameter: {“data” : false} when the current user’s changes are sent to the document editing service.

    Example

    1. var onDocumentStateChange = function (event) {
    2. if (event.data) {
    3. console.log("The document changed");
    4. } else {
    5. console.log("Changes are collected on document editing service");
    6. }
    7. };
    8. var docEditor = new DocsAPI.DocEditor("placeholder", {
    9. "events": {
    10. "onDocumentStateChange": onDocumentStateChange,
    11. ...
    12. },
    13. ...
    14. });
  • onDownloadAs - the function called with the absolute URL to the edited file when the downloadAs method is being called. The absolute URL to the document to be downloaded and its type are sent in the data parameter.

    Example

    1. var onDownloadAs = function (event) {
    2. var fileType = event.data.fileType;
    3. var url = event.data.url;
    4. console.log("ONLYOFFICE Document Editor create file: " + url);
    5. };
    6. var docEditor = new DocsAPI.DocEditor("placeholder", {
    7. "events": {
    8. "onDownloadAs": onDownloadAs,
    9. ...
    10. },
    11. ...
    12. });
  • onError - the function called when an error or some other specific event occurs. The error message is sent in the data parameter.

    Example

    1. var onError = function (event) {
    2. console.log("ONLYOFFICE Document Editor reports an error: code " + event.data.errorCode + ", description " + event.data.errorDescription);
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onError": onError,
    7. ...
    8. },
    9. ...
    10. });
  • onInfo - the function called when the application opened the file. The mode is sent in the data.mode parameter. Can be view or edit.

    Example

    1. var onInfo = function (event) {
    2. console.log("ONLYOFFICE Document Editor is opened in mode " + event.data.mode);
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onInfo": onInfo,
    7. ...
    8. },
    9. ...
    10. });
  • onMetaChange - the function called when the meta information of the document is changed via the meta command. The name of the document is sent in the data.title parameter. The Favorite icon highlighting state is sent in the data.favorite parameter. When the user clicks the Favorite icon, the setFavorite method is called to update the information about the Favorite icon highlighting state. If the method is not declared, the Favorite icon will not be changed.

    Example

    1. var onMetaChange = function (event) {
    2. var title = event.data.title;
    3. var favorite = event.data.favorite;
    4. ...
    5. };
    6. var docEditor = new DocsAPI.DocEditor("placeholder", {
    7. "events": {
    8. "onMetaChange": onMetaChange,
    9. ...
    10. },
    11. ...
    12. });
  • onMakeActionLink - the function called when the user is trying to get link for opening the document which contains a bookmark, scrolling to the bookmark position. To set the bookmark link you must call the setActionLink method. The bookmark data is received in the data parameter and must be then used in the configuration as the value for the editorConfig.actionLink parameter. If the method is not declared the Get Link button will not be displayed.

    onMakeActionLink

    Example

    1. var onMakeActionLink = function (event){
    2. var ACTION_DATA = event.data;
    3. ...
    4. var link = GENERATE_LINK(ACTION_DATA);
    5. docEditor.setActionLink(link);
    6. };
    7. var docEditor = new DocsAPI.DocEditor("placeholder", {
    8. "events": {
    9. "onMakeActionLink": onMakeActionLink,
    10. ...
    11. },
    12. ...
    13. });
  • onOutdatedVersion - the function called after the error is shown, when the document is opened for editing with the old document.key value, which was used to edit the previous document version and was successfully saved. When this event is called the editor must be reinitialized with a new document.key.

    Example

    1. var onOutdatedVersion = function () {
    2. location.reload(true);
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onOutdatedVersion": onOutdatedVersion,
    7. ...
    8. },
    9. ...
    10. });
  • onPluginsReady - the function called when all plugins are loaded and can be used.

    Example

    1. var onPluginsReady = function () {
    2. ...
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onPluginsReady": onPluginsReady,
    7. ...
    8. },
    9. ...
    10. });
  • onReady - the function called when the application is loaded into the browser. Deprecated since version 5.0, please use onAppReady instead

  • onRequestClose - the function called when the work with the editor must be ended and the editor must be closed.

    Example

    1. var onRequestClose = function () {
    2. if (window.opener) {
    3. window.close();
    4. return;
    5. }
    6. docEditor.destroyEditor();
    7. };
    8. var docEditor = new DocsAPI.DocEditor("placeholder", {
    9. "events": {
    10. "onRequestClose": onRequestClose,
    11. ...
    12. },
    13. ...
    14. });
  • onRequestCompareFile* - the function called when the user is trying to select document for comparing by clicking the Document from Storage button. To select a document for comparing you must call the setRevisedFile method. If the method is not declared the Document from Storage button will not be displayed. * - available only for ONLYOFFICE Enterprise Edition and ONLYOFFICE Developer Edition

    onRequestCompareFile

    Example

    1. var onRequestCompareFile = function () {
    2. docEditor.setRevisedFile({
    3. "fileType": "docx",
    4. "url": "https://example.com/url-to-example-document.docx"
    5. });
    6. };
    7. var docEditor = new DocsAPI.DocEditor("placeholder", {
    8. "events": {
    9. "onRequestCompareFile": onRequestCompareFile,
    10. ...
    11. },
    12. ...
    13. });

    Where the example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

  • onRequestCreateNew - the function called when the user is trying to create document by clicking the Create New button. This method is used instead of the createUrl field. If the method is not declared and the createUrl is not specified the Create New button will not be displayed.

    Example

    1. var onRequestCreateNew = function () {
    2. ...
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onRequestCreateNew": onRequestCreateNew,
    7. ...
    8. },
    9. ...
    10. });
  • onRequestEditRights - the function called when the user is trying to switch the document from the viewing into the editing mode by clicking the Edit Document button. When the function is called, the editor must be initialized again, in editing mode. If the method is not declared the Edit button will not be displayed.

    onRequestEditRights parameter is obligatory when the editorConfig mode parameter is set to view and the permission to edit the document (document permissions) is set to true so that the user could switch to the editing mode.

    onRequestEditRights

    Example

    1. var onRequestEditRights = function () {
    2. console.log("ONLYOFFICE Document Editor requests editing rights");
    3. document.location.reload();
    4. };
    5. var docEditor = new DocsAPI.DocEditor("placeholder", {
    6. "events": {
    7. "onRequestEditRights": onRequestEditRights,
    8. ...
    9. },
    10. ...
    11. });
  • onRequestHistory - the function called when the user is trying to show the document version history by clicking the Version History button. To show the document version history you must call the refreshHistory method. If the method and the onRequestHistoryData method is not declared the Version History button will not be displayed.

    onRequestHistory

    Example

    1. var onRequestHistory = function () {
    2. docEditor.refreshHistory({
    3. "currentVersion": 2,
    4. "history": [
    5. {
    6. "changes": changes,
    7. "created": "2010-07-06 10:13 AM",
    8. "key": "af86C7e71Ca8",
    9. "serverVersion": serverVersion,
    10. "user": {
    11. "id": "F89d8069ba2b",
    12. "name": "Kate Cage"
    13. },
    14. "version": 1
    15. },
    16. {
    17. "changes": changes,
    18. "created": "2010-07-07 3:46 PM",
    19. "key": "Khirz6zTPdfd7",
    20. "user": {
    21. "id": "78e1e841",
    22. "name": "John Smith"
    23. },
    24. "version": 2
    25. },
    26. ...
    27. ]
    28. });
    29. };
    30. var docEditor = new DocsAPI.DocEditor("placeholder", {
    31. "events": {
    32. "onRequestHistory": onRequestHistory,
    33. ...
    34. },
    35. ...
    36. });

    Where the changes is the changes from the history object returned after saving the document.

    Where the serverVersion is the serverVersion from the history object returned after saving the document.

  • onRequestHistoryClose - the function called when the user is trying to go back to the document from viewing the document version history by clicking the Close History button. When the function is called, the editor must be initialized again, in editing mode. If the method is not declared the Close History button will not be displayed.

    onRequestHistoryClose

    Example

    1. var onRequestHistoryClose = function () {
    2. document.location.reload();
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onRequestHistoryClose": onRequestHistoryClose,
    7. ...
    8. },
    9. ...
    10. });
  • onRequestHistoryData - the function called when the user is trying to click the specific document version in the document version history. To show the changes corresponding to the specific document version you must call the setHistoryData method. The document version number is sent in the data parameter. If the method and the onRequestHistory method is not declared the Version History button will not be displayed.

    onRequestHistoryData

    Example

    1. var onRequestHistoryData = function (event) {
    2. var version = event.data;
    3. docEditor.setHistoryData({
    4. "changesUrl": "https://example.com/url-to-changes.zip",
    5. "fileType": "docx",
    6. "key": "Khirz6zTPdfd7",
    7. "previous": {
    8. "fileType": "docx",
    9. "key": "af86C7e71Ca8",
    10. "url": "https://example.com/url-to-the-previous-version-of-the-document.docx"
    11. },
    12. "url": "https://example.com/url-to-example-document.docx",
    13. "version": version
    14. })
    15. };
    16. var docEditor = new DocsAPI.DocEditor("placeholder", {
    17. "events": {
    18. "onRequestHistoryData": onRequestHistoryData,
    19. ...
    20. },
    21. ...
    22. });

    Where the changesUrl is the changesUrl from the JSON object returned after saving the document.

    Where the example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

  • onRequestInsertImage - the function called when the user is trying to insert an image by clicking the Image from Storage button. The type of image insertion is specified in parameter data.c. To insert an image into the file you must call the insertImage method with the specified command. If the method is not declared the Image from Storage button will not be displayed.

    onRequestInsertImage

    Example

    1. var onRequestInsertImage = function (event) {
    2. docEditor.insertImage({
    3. "c": event.data.c,
    4. "images": [
    5. {
    6. "fileType": "png",
    7. "url": "https://example.com/url-to-example-image1.png"
    8. },
    9. {
    10. "fileType": "png",
    11. "url": "https://example.com/url-to-example-image2.png"
    12. },
    13. ...
    14. ]
    15. });
    16. };
    17. var docEditor = new DocsAPI.DocEditor("placeholder", {
    18. "events": {
    19. "onRequestInsertImage": onRequestInsertImage,
    20. ...
    21. },
    22. ...
    23. });

    Where the example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

  • onRequestMailMergeRecipients - the function called when the user is trying to select recipients data by clicking the Mail merge button. To select recipient data, you must call the setMailMergeRecipients method. If the method is not declared, the Mail merge button will become faded and unclickable.

    onRequestMailMergeRecipients

    Example

    1. var onRequestMailMergeRecipients = function () {
    2. docEditor.setMailMergeRecipients({
    3. "fileType": "xlsx",
    4. "url": "https://example.com/url-to-example-recipients.xlsx"
    5. });
    6. };
    7. var docEditor = new DocsAPI.DocEditor("placeholder", {
    8. "events": {
    9. "onRequestMailMergeRecipients": onRequestMailMergeRecipients,
    10. ...
    11. },
    12. ...
    13. });

    Where the example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

  • onRequestReferenceData - the function called when the user is trying to refresh data inserted from the external file by clicking the Update values button in the External links dialog box of the Data tab. To refresh data by a link to a file which is specified with the event parameters, you must call the setReferenceData method. An object with the unique file data and the file path or name are sent in the data parameter. If the event is not declared, the Paste link and Update values buttons will not be displayed.

    To send the data to the setReferenceData method, it is recommended to search for the file by the referenceData parameter first. If there is no such a field or a file cannot be found, then the path parameter is used.

    Paste link

    Update values

    Example

    1. var onRequestReferenceData = function () {
    2. var referenceData = event.data.referenceData;
    3. var path = event.data.path;
    4. ...
    5. docEditor.setReferenceData({
    6. "fileType": "xlsx",
    7. "path": "sample.xlsx",
    8. "referenceData": {
    9. "fileKey": "BCFA2CED",
    10. "instanceId": "https://example.com"
    11. },
    12. "url": "https://example.com/url-to-example-document.xlsx"
    13. });
    14. };
    15. var docEditor = new DocsAPI.DocEditor("placeholder", {
    16. "events": {
    17. "onRequestReferenceData": onRequestReferenceData,
    18. ...
    19. },
    20. ...
    21. });
  • onRequestRename - the function called when the user is trying to rename the file by clicking the Rename… button.

    Until version 6.0 the Rename… button is only available if the document.permissions.rename is set to true.

    onRequestRename

    Example

    1. var onRequestRename = function (event) {
    2. var title = event.data;
    3. ...
    4. };
    5. var docEditor = new DocsAPI.DocEditor("placeholder", {
    6. "events": {
    7. "onRequestRename": onRequestRename,
    8. ...
    9. },
    10. ...
    11. });
  • onRequestRestore - the function called when the user is trying to restore the file version by clicking the Restore button in the version history. When the function is called, you must call the refreshHistory method to initialize version history again. The document version number is sent in the data.version parameter if it is called for the document version from the history. Additionally, the document link is sent in the data.url parameter if it is called for the document changes from the history object. The type of the document which is specified with this link is sent in the data.fileType parameter. If the method is not declared the Restore button will not be displayed.

    The Restore button is displayed for the previous document versions only and hidden for the current one. Until version 5.5 the Restore button is only available if the document.permissions.changeHistory is set to true.

    onRequestRestore

    Example

    1. var onRequestRestore = function (event) {
    2. var fileType = event.data.fileType;
    3. var url = event.data.url;
    4. var version = event.data.version;
    5. ...
    6. docEditor.refreshHistory({
    7. "currentVersion": 2,
    8. "history": [
    9. {
    10. "changes": changes,
    11. "created": "2010-07-06 10:13 AM",
    12. "key": "af86C7e71Ca8",
    13. "serverVersion": serverVersion,
    14. "user": {
    15. "id": "F89d8069ba2b",
    16. "name": "Kate Cage"
    17. },
    18. "version": 1
    19. },
    20. {
    21. "changes": changes,
    22. "created": "2010-07-07 3:46 PM",
    23. "key": "Khirz6zTPdfd7",
    24. "user": {
    25. "id": "78e1e841",
    26. "name": "John Smith"
    27. },
    28. "version": 2
    29. },
    30. ...
    31. ]
    32. });
    33. };
    34. var docEditor = new DocsAPI.DocEditor("placeholder", {
    35. "events": {
    36. "onRequestHistoryData": onRequestHistoryData,
    37. ...
    38. },
    39. ...
    40. });

    Where the changes is the changes from the history object returned after saving the document.

    Where the serverVersion is the serverVersion from the history object returned after saving the document.

    Where the example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

  • onRequestSaveAs - the function called when the user is trying to save file by clicking Save Copy as… button. The title of the document, its type and the absolute URL to the document to be downloaded are sent in the data parameter. If the method is not declared the Save Copy as… button will not be displayed.

    onRequestSaveAs

    Example

    1. var onRequestSaveAs = function (event) {
    2. var fileType = event.data.fileType;
    3. var title = event.data.title;
    4. var url = event.data.url;
    5. ...
    6. };
    7. var docEditor = new DocsAPI.DocEditor("placeholder", {
    8. "events": {
    9. "onRequestSaveAs": onRequestSaveAs,
    10. ...
    11. },
    12. ...
    13. });
  • onRequestSendNotify - the function called when the user is mentioned in a comment. The list of users to be mentioned should be completed by setUsers method. The message and the list of emails is sent in the data parameter. The comment data is received in the data.actionLink parameter and must be then used in the configuration as the value for the editorConfig.actionLink parameter.

    In version 5.4, onRequestSendNotify event can only be used if onRequestUsers event is set. Starting from version 5.5, there is no such dependency between onRequestSendNotify and onRequestUsers - both can be set independently.

    Example

    1. var onRequestSendNotify = function (event) {
    2. var ACTION_DATA = event.data.actionLink;
    3. var comment = event.data.message;
    4. var emails = event.data.emails;
    5. ...
    6. };
    7. var docEditor = new DocsAPI.DocEditor("placeholder", {
    8. "events": {
    9. "onRequestSendNotify": onRequestSendNotify,
    10. ...
    11. },
    12. ...
    13. });
  • onRequestSharingSettings - the function called when the user is trying to manage document access rights by clicking Change access rights button. When the access rights is changed, you must call the setSharingSettings method to update the information about the settings which allow to share the document with other users. If the method is not declared the Change access rights button will not be displayed.

    onRequestSharingSettings

    Example

    1. var onRequestSharingSettings = function () {
    2. docEditor.setSharingSettings({
    3. "sharingSettings": [
    4. {
    5. "permissions": "Full Access",
    6. "user": "John Smith"
    7. },
    8. {
    9. "isLink": true,
    10. "permissions": "Read Only",
    11. "user": "External link"
    12. }
    13. ]
    14. });
    15. ...
    16. };
    17. var docEditor = new DocsAPI.DocEditor("placeholder", {
    18. "events": {
    19. "onRequestSharingSettings": onRequestSharingSettings,
    20. ...
    21. },
    22. ...
    23. });
  • onRequestUsers - the function called when the commenter can select other users for mention in the comments. To set the users list you must call the setUsers method.

    onRequestUsers

    Example

    1. var onRequestUsers = function () {
    2. docEditor.setUsers({
    3. "users": [
    4. {
    5. "email": "john@example.com",
    6. "name": "John Smith"
    7. },
    8. {
    9. "email": "kate@example.com",
    10. "name": "Kate Cage"
    11. },
    12. ...
    13. ]
    14. });
    15. };
    16. var docEditor = new DocsAPI.DocEditor("placeholder", {
    17. "events": {
    18. "onRequestUsers": onRequestUsers,
    19. ...
    20. },
    21. ...
    22. });
  • onWarning - the function called when a warning occurs. The warning message is sent in the data parameter.

    Example

    1. var onWarning = function (event) {
    2. console.log("ONLYOFFICE Document Editor reports a warning: code " + event.data.warningCode + ", description " + event.data.warningDescription);
    3. };
    4. var docEditor = new DocsAPI.DocEditor("placeholder", {
    5. "events": {
    6. "onWarning": onWarning,
    7. ...
    8. },
    9. ...
    10. });