最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - tinymce 4 how to add event handler - Stack Overflow

programmeradmin3浏览0评论

In tinymce 3, it seems that we can do this with :

// Adds a click handler to the current document
tinymce.dom.Event.add(document, 'click', function(e) {
   console.debug(e.target);
});

What is the syntax in tinymce 4 ?
Need to do it after tinymce initialized.

UPDATE : I tried (still don't work)

tinymce.bind("description", "keyup", function () {
  console.debug('here');
});

In tinymce 3, it seems that we can do this with :

// Adds a click handler to the current document
tinymce.dom.Event.add(document, 'click', function(e) {
   console.debug(e.target);
});

What is the syntax in tinymce 4 ?
Need to do it after tinymce initialized.

UPDATE : I tried (still don't work)

tinymce.bind("description", "keyup", function () {
  console.debug('here');
});
Share Improve this question edited Nov 5, 2013 at 15:29 Hendry H. asked Nov 5, 2013 at 15:21 Hendry H.Hendry H. 1,5203 gold badges14 silver badges28 bronze badges 3
  • Have a look at the docs. tinymce./wiki.php/api4:method.tinymce.dom.DOMUtils.bind – Ben Fortune Commented Nov 5, 2013 at 15:25
  • Yes I tried that. Still not working. I updated my question. See any mistake in my code ? – Hendry H. Commented Nov 5, 2013 at 15:30
  • Wow, made a mistake there myself. God, that API doc is plicated to read. Alright, correct answer now below, and is tested... You just forgot the DOM (uppercase !important) in your code. – Florian Rachor Commented May 14, 2014 at 9:05
Add a ment  | 

3 Answers 3

Reset to default 9

This works :

tinymce.activeEditor.on('keyup', function(e) {
    console.debug("keyup");
});

Just to follow up on this, if anybody stumbles upon this in future. This in the old API:

tinymce.dom.Event.add(document, 'click', function(e) {
 console.debug(e.target);
});

Would now be correctly:

tinymce.DOM.bind(document, 'click', function(e) {
 console.debug(e.target);
});

So if you are getting the "undefined is not a function" error on .add this should solve your problem.

I needed the 'keyup' event to fire. This is how I got it to work:

let editor = tinymce.get("my_textarea_id");
editor.contentDocument.addEventListener('keyup', function (e) { 
   console.debug("keyup");    });
发布评论

评论列表(0)

  1. 暂无评论