HTML onclose Event Attribute
HTML Event AttributeThis event attribute is supported by all modern browsers.
Description
The onclose event attribute runs a script when a <dialog> element has been closed, in any way: with the close() or requestClose() methods, with a form that uses method="dialog", with a button that has command="close", or by the user pressing Esc.
The event is not cancelable; it fires after the dialog is already closed. Read dialog.returnValue in the handler to find out how the dialog was closed, for example which button of a method="dialog" form was used. To stop a dialog from being dismissed, use oncancel instead.
<dialog id="confirm" onclose="console.log(this.returnValue)">
<form method="dialog">
<button value="yes">Yes</button>
<button value="no">No</button>
</form>
</dialog>
Syntax
<element onclose="script">
Values
- scriptThe name of the script to use when the event has been triggered.
Example
Browser Support
The following information will show you the current browser support for the HTML onclose event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.
This event attribute is supported by all modern browsers.
Desktop





Tablets & Mobile






-
Supported Unknown Not supported
Sponsors
Password Manager
PasswordPal stores your passwords and private notes behind encryption that happens in your browser.
Copy Paste List
Copy and paste or download lists in your preferred format, including plain text, PDF, or HTML.
Unicode Characters & Emojis
Search all Unicode characters and emojis plus other tools.
Check Shortened URLs
Expand shortened URLs to view the destination link.
Advertise Here
Advertise your company and products here!