Check this dialog box implementation.
const open = document.getElementById('open')const dlg = document.getElementById('dlg')open.addEventListener('click', function () { dlg.showModal()})dlg.addEventListener('close', function () { console.log('You chose:', dlg.returnValue)})<button id="open">Open</button><dialog id="dlg"><form method="dialog"><p>Are you sure?</p><button value="no">No</button><button value="yes">Yes</button></form></dialog>Follow these steps:
- Run the above code snippet.
- Click "Open" button.
- Click "No" in the dialog box.
- The console log shows
You chose: no. - Click "Open" button again.
- Cancel the dialog box by pressing Esc.
- The console log shows
You chose: no.
On Firefox v143, step 7 prints:
You chose: noOn Chrome v140, step 7 prints:
You chose:Is the value of returnValue when we cancel the dialog box with Esc left undefined in the spec? Or does the spec specify the returnValue in this situation?