skip to Main Content

I have a page with multiple <dialog> elements, which I open as modal using their showModal() methods.

I want to detect whether any of them is currently opened from Javascript (since some event handlers shouldn’t trigger when a modal is opened). Is it possible to check if modal is currently opened? Maybe through existance of dialog::backdrop or checking someway for inertness of non-modal content?

2

Answers


  1. Chosen as BEST ANSWER

    When dialog is opened as modal, it gets CSS pseudo-class :modal - so it can be queried with selector:

    document.querySelector("dialog:modal") === null; // No dialog is opened as modal.
    document.querySelector("dialog:modal") !== null; // Some dialog is opened as modal.
    

  2. You can use Garnish.Modal.visibleModal to check if a modal is visible and which one.

    Garnish Model

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search