Common operations
Updated at:
Use the IMM WebOffice JavaScript SDK to subscribe to document events, retrieve the SDK version, and access the document URL and iframe element.
List available events
The Events property returns all event names you can subscribe to.
async function example() {
await instance.ready();
const events = await instance.Events;
console.log(events);
}
Listen to events
Use on(eventName, handler) to subscribe to an event. The handler receives the event object when the event fires.
async function example() {
await instance.ready();
// Save the handler reference so you can unsubscribe later
const onFileSaved = (e) => console.log(e);
instance.on('fileSaved', onFileSaved);
}
Note: Save the handler as a named variable. Passing an anonymous function toon()makes it impossible to unsubscribe later withoff().
Stop listening to events
Use off(eventName, handler) to unsubscribe from an event. Pass the same function reference used in on()—passing a different function has no effect.
async function example() {
await instance.ready();
const onResponse = (e) => console.log(e);
// Subscribe
instance.on('response', onResponse);
// Unsubscribe using the same reference
await instance.off('response', onResponse);
}
Check the SDK version
The version property returns the current SDK version.
async function example() {
await instance.ready();
const version = await instance.version;
console.log(version);
}
Get the document URL
The url property returns the actual path of the document, which is the value of url nested in iframe.
async function example() {
await instance.ready();
const url = await instance.url;
console.log(url);
}
Get the iframe element
The iframe property returns the iframe DOM element for the current document instance.
async function example() {
await instance.ready();
const iframe = await instance.iframe;
console.log(iframe);
}
Is this page helpful?