Information related to the events OSM exposes
Our JavaScript SDK includes an event handler that allows you to listen for specific events related to the informational modal and specify a callback function to be triggered when those events occur.
The event handler can be used by calling the following function:
window.Klarna.OnsiteMessaging.on(event: EventType, callback: function)
The event handler supports the following events:
If either the EventType or callback parameter is not provided, the function will log an error on the console but will not throw an error to avoid causing issues on the page. If it is passed a string for EventType that is not supported, the function will also log an error as well.
Here are is an example of how the window.Klarna.OnsiteMessaging.on
function might be used:
Blocking the scrolling of the background when the informational modal is opened
window.Klarna.OnsiteMessaging.on('informationalModalOpened', function() {
document.body.style.overflow = 'hidden';
});
window.Klarna.OnsiteMessaging.on('informationalModalClosed', function() {
document.body.style.overflow = 'auto';
});
In this example, the merchant is using the informationalModalOpened and informationalModalClosed events to block the scrolling of the background when the interstitial is opened and restore it when the interstitial is closed.