javascriptjqmodal

Need help to implement CloseOnEscape Key Press for JQModal with IFrame


I am using JqModal in my project. Its a nice JS modal. However i need one help to attach an Close On Escape key press to the JqModal. I am loading eternal content from external URL in JqModal.

For simple Modal where no IFrame is used, its very easy to implement the CloseOnEscape key press feature.


Solution

  • I made it work by updating the jqModal.js file

    Steps:

    1. Add option "closeOnEsc: true" to the jqModal. So the option will look something like this,

          var p = {
          overlay: 50,
          overlayClass: 'jqmOverlay',
          closeClass: 'jqmClose',
          trigger: '.jqModal',
          ajax: F,
          ajaxText: '',
          target: F,
          modal: F,
          toTop: F,
          onShow: F,
          onHide: F,
          onLoad: F,
          closeOnEsc: true
      };
      
    2. Add following code to the jqModal open function.

          var modal = $(h.w);
      
          modal.unbind("keydown");
      
          if (c.closeOnEsc) {
              modal.attr("tabindex", 0);
              modal.bind("keydown", function (event) {
                  if (event.keyCode == 27) {
                      event.preventDefault();                        
                      modal.jqmHide();
                  }
              });
              modal.focus();
          }