There are similar questions asked. But I tried all possible solutions for those questions and none of them worked. I have a dojo modal and I want to capture both the close event 'X' at the top right and also the 'escape' key press event. Below is my code.
<script>
dojo.connect(dojo.byId("myDialog"),"onCancel", function(){
alert("Hi");
});
document.body.addEventListener('keypress', function(e) {
if (e.key == "Escape") {
alert("Hi");
}
});
</script>
<div class="myDialogClass" id="myDialog" name="myDialog" role="dialog" style="display:none" dojoType="dijit/Dialog" closeOnTimeOut="false" parseOnLoad="true" title="Title">
</div>
I tried all the below solutions, and none of them worked
1. dojo.connect(dojo.byId("myDialog"),"onHide"
2. dojo.connect(dojo.byId("myDialog"),"hide"
3. myDialog.connect(myDialog, "hide", function(e){
dijit.byId("user_submit").destroy(); });
4. <script type="dojo/method" event="onClose"> console.log('closed')
</script>*, *<script type="dojo/method" event="onCancel">
console.log('closed') </script>
5. var myDialog = new Dialog({ id: "myDialogId1", onHide:
function() {
myDialog.destroy() }
});
Any help is much appreciated.