javascript - Enter keypress is not detected on keypress function -


i trying detect enter key press inside tinmyce editor , it's working fine keys not working enter key.

setup : function (instance) {      instance.on("keypress", function(e) {              var keycode = (e.keycode ? e.keycode : e.which);              alert(keycode);         }); } 

in above code alerting keys except enter. don't know whats issue there.

i think work, i've tested , works in fiddle jquery 2.24

$(document).keypress(function(e) {    if (e.which == 13) {      console.log('you pressed enter!');    } else {      console.log('you pressed ' + e.which);    }    });
body {    height: 500px;    width:500px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <body>       </body>

edit: sorry noticed after tagged tinymce

i think can adjusting function

//tinymce.init({  setup : function(instance) {       instance.onkeydown.add(function(instance, event) {            if (event.keycode == 13)  {  //enter               event.preventdefault();               event.stoppropagation();              //do stuff here             //alert("enter!");           }           else{ alert (event.keycode);}       });    } //}); 

edit 2: in current tiny mce docs, there example of function [in setup].

maybe try

tinymce.init({   selector: 'textarea',  // change value according html   setup: function(instance) {     instance.on('keypress', function(e) {       if (event.keycode == 13)  {  //enter                   event.preventdefault();                   event.stoppropagation();                  //do stuff here                 //alert("enter!");               }               else{ alert (event.keycode);}     });   } }); 

note tinymce lowercase..


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -