CustomizationCallbacks & 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().

This is the one callback that behaves exactly as documented.

Signature

interface MedosBookingConfig {
  onClose?: () => void;
}

Modal-only. Never fires in inline mode.

Common patterns

Release a scroll lock you applied

The widget doesn't lock body scroll itself, so if you froze the page when opening the modal, onClose is where you undo it:

document.querySelector("#book-btn").onclick = () => {
  document.body.style.overflow = "hidden";
  MedosBooking.open();
};

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();
};

The abandoned-booking pattern can't work yet

It depends on onSuccess to set bookedInThisSession, and onSuccess doesn't currently fire. As things stand every close looks abandoned, including successful bookings. Keep the shape in mind, but don't ship conversion reporting on it.

On this page