After document in iframe reloads, previously listened events no longer work
Answer:
Event listener information is stored in SDK and also stored in the document page. Document reload will not retain previous listeners, meaning the copy stored in the document is lost. After document reloads, listeners need to be re-added.
Since users may not know from code level when the document reloads, here is the most reliable event listening solution:
Listen to document save event in ZOfficeSDK.addListener document open callback, the former is not affected by document reload. After document reloads, other event listeners not working issues can all be solved through this method.
// Listen to events every time document opens; i.e., listen to desired events in FileOpen event callback
var app;
ZOfficeSDK.addListener('.my-doc-editor','IDOCS.Event.FileOpen', async () => {
console.log('file open')
app = await ZOfficeSDK.connect('.my-doc-editor');
await app.ready();
// Listen to document save event
Application.addListener('IDocs.Event.FileStatus', (data) => {
console.log("FileStatus: ", data);
});
})
ZOfficeSDK.mount('http://111.30.26.225:8001/docs/app/sCWVriqjtmkfQx4N/1972968612766756865/edit/content?token=d0269723-eee1-4861-bbd8-48c9e940070b', '.my-doc-editor',true)