Windows equivalent.showModalDialog for Google Chrome

Asked

Viewed 1,189 times

1

Hello, I need a way equivalent to window.showModalDialog to open as modal and wait for her return to continue the source, when I give an open it is asynchronous of my site and does not work together.

ps window.showModalDialog works on IE

1 answer

1

Hello, according to the Mozilla documentation this Feature is already obsolete and has been removed from Chrome and Firefox.

You can now use the tag <dialog>.

Excerpt from the documentation itself

HTML

<!-- Simple pop-up dialog box, containing a form -->
  <dialog open id="favDialog">
    <form method="dialog">
      <section>
        <p><label for="favAnimal">Favorite animal:</label>
        <select id="favAnimal">
          <option></option>
          <option>Brine shrimp</option>
          <option>Red panda</option>
          <option>Spider monkey</option>
        </select></p>
      </section>
      <menu>
        <button id="cancel" type="reset">Cancel</button>
        <button type="submit">Confirm</button>
      </menu>
    </form>
  </dialog>

  <menu>
    <button id="updateDetails">Update details</button>
  </menu>

JS

(function() {
  var updateButton = document.getElementById('updateDetails');
  var cancelButton = document.getElementById('cancel');
  var favDialog = document.getElementById('favDialog');

  // Update button opens a modal dialog
  updateButton.addEventListener('click', function() {
    favDialog.showModal();
  });

  // Form cancel button closes the dialog box
  cancelButton.addEventListener('click', function() {
    favDialog.close();
  });
})();

Documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog https://developer.mozilla.org/en-US/docs/Web/API/Window/showModalDialog

Browser other questions tagged

You are not signed in. Login or sign up in order to post.