When user click on close tab, display error if form is not validate

When user click on close tab, display error if form is not validate

Would you please give a solution for this: When user click on the close tab of the browser, display error if the form is not validated.