WidgetsBooking widgetCallbacks

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 automatic close 3 seconds after a booking completes, which follows onSuccess.

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:

let started = false;

document.querySelector("#book-btn").onclick = () => {
  document.body.style.overflow = "hidden";
  // init() in modal mode opens straight away: run it on the first click only.
  if (started) return MedosBooking.open();
  started = true;
  MedosBooking.init({
    apiKey: "mk_...",
    mode: "modal",
    onClose: () => {
      document.body.style.overflow = "";
    },
  });
};

Track "abandoned booking"

let started = false;
let opened = false;
let bookedInThisSession = false;

const config = {
  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;
  if (started) return MedosBooking.open();
  started = true;
  MedosBooking.init(config);
};

Order matters here

A successful booking fires onSuccess first and onClose 3 seconds later, so bookedInThisSession is already true by the time the close handler reads it. That ordering is what keeps a completed booking from being counted as an abandoned one.

On this page