1

I have an lwc component with a form in it. I want to fire an onbeforeunload event when pressing "discard", to show the stanard chrome modal.

Is it possible in lightning web components?

1 Answer 1

2

You can't use beforeunload for that purpose. It would only fire when the user leaves salesforce completely. You can use a normal onclick handler with the confirm method:

cancel(event) {
  if(confirm('Discard your changes?')) {
    // navigate away now
  } else {
    event.preventDefault();
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .