Functions
The Website Widget exposes a set of functions on the global window.Kapa
object, allowing you to manipulate it programmatically. The following functions are available:
To call these functions, the window.Kapa
object must be initialized first.
Use preinitialization to prevent errors when functions
are called before the widget object has completed initialization.
open
Open the widget modal.
Optional parameters:
Parameter | Type | Default | Description |
---|---|---|---|
mode | 'search' | 'ai' | 'ai' | The mode the widget is set to when the modal is opened. |
query | string | '' | Opens the widget with this query prefilled. |
submit | boolean | false | Automatically submit the query when the model is opened. |
Example usage:
window.Kapa.open({
mode: "ai",
query: "How to get started?",
submit: true,
});
close
Close the widget modal.
Example usage:
window.Kapa.close();
render
Mounts the global Kapa
object. This operation is asynchronous, so any
subsequent function calls that depend on the widget being fully initialized
should be executed only after render()
has completed, typically by using the
provided onRender
callback.
Optional parameters:
Parameter | Type | Default | Description |
---|---|---|---|
onRender | function | Callback function to invoke when the widget has rendered. |
Example usage:
window.Kapa.render({
onRender: () => window.Kapa.open(),
});
unmount
Unmounts the global Kapa
object, removing its rendered DOM elements and
clearing all references to it.
window.Kapa.unmount()