admin管理员组

文章数量:1291145

i am working on a html page having an modal then if modal loads on page then if i press ESC key then modal closed , that is very unliking to me. how to prevent this.?? please note that modal using cakephp render. i tried this , but not working

$(document).keydown(function(e) {
    if (e.keyCode == 27) return false;
});

i am working on a html page having an modal then if modal loads on page then if i press ESC key then modal closed , that is very unliking to me. how to prevent this.?? please note that modal using cakephp render. i tried this , but not working

$(document).keydown(function(e) {
    if (e.keyCode == 27) return false;
});
Share Improve this question edited Aug 6, 2015 at 9:58 Manish Prajapati asked Aug 6, 2015 at 9:17 Manish PrajapatiManish Prajapati 1,6412 gold badges14 silver badges21 bronze badges 5
  • Where is the code of your modal? Post it here – hindmost Commented Aug 6, 2015 at 9:18
  • are you usig jquery dialog or bootstrap modal? please post your code. – Umesh Sehta Commented Aug 6, 2015 at 9:23
  • i am using bootstrap modal. – Manish Prajapati Commented Aug 6, 2015 at 9:40
  • 1 i am using bootstrap modal. Then you have to indicate this in the question as well as in tags – hindmost Commented Aug 6, 2015 at 9:44
  • possible duplicate of How to disable Escape Key for Twitter Bootstrap Modals? – hindmost Commented Aug 6, 2015 at 9:48
Add a ment  | 

1 Answer 1

Reset to default 8

add this attribute in your modal div

data-keyboard="false"

Example

<div id="myModal" data-keyboard="false">

</div> 

本文标签: javascriptHow to disable ESC key on ModalStack Overflow