Use an alert modal to halt users and communicate an urgent error that’s affecting their system, feature, or page. To display an alert modal in Lightning Experience, import
LightningAlert from the
lightning/alert module, and call
LightningAlert.open() with your desired attributes.
This alert modal is an alternative to the native
window.alert() function, which isn’t supported for cross-origin iframes in Chrome and Safari. Unlike the native alert function,
LightningAlert.open() doesn't halt execution on the page, it returns a Promise. Use
.then() for any code you want to execute after the modal is closed.
This example component creates a button that opens the alert modal UI that you see in the screenshot. Typically, an error condition would trigger display of the alert modal.
LightningAlert event with
label attributes. The
.open() function returns a promise that resolves when you click OK.
For information about the attributes for the alert modal, see the Component Reference.