Callbacks & Events
onClose
Fires when the modal is closed. Modal mode only.
onClose fires whenever the modal-mode widget is dismissed — whether by:
- The patient clicking the × button.
- The patient clicking the backdrop.
- Your code calling
MedosBooking.close(). - The 3-second auto-close after a successful booking.
Signature
onClose?: () => void;Modal-only. Never fires in inline mode.
Common patterns
Restore page state
MedosBooking.init({
apiKey: "mk_...",
mode: "modal",
onClose: () => {
document.body.style.overflow = "";
},
});Track "abandoned booking"
let opened = false;
let bookedInThisSession = false;
MedosBooking.init({
apiKey: "mk_...",
mode: "modal",
onSuccess: () => {
bookedInThisSession = true;
},
onClose: () => {
if (opened && !bookedInThisSession) {
window.dataLayer?.push({ event: "medos_booking_abandoned" });
}
opened = false;
bookedInThisSession = false;
},
});
document.querySelector("#book-btn").onclick = () => {
opened = true;
MedosBooking.open();
};Success also fires onClose
Because the modal auto-closes 3 seconds after a booking, onClose fires
even for successful sessions. If you're distinguishing "abandoned" from
"booked", track a bookedInThisSession flag in onSuccess — see the
pattern above.