I guess the keyup
event is too late.
If you use the keypress
event instead of keyup
, then this seems to work:
ed.on( 'keypress', function(e) {
var content = ed.getContent().replace(
/(<[a-zA-Z\/][^<>]*>|\[([^\]]+)\])|(\s+)/ig, '' );
var max = 20;
var len = content.length;
var diff = max - len;
if ( diff < 1 )
tinymce.dom.Event.cancel(e);
document.getElementById("character_count").innerHTML = "Characters Left: " + diff;
} );
The keypress
event will not log keys like Alt, Enter, Control, ArrowUp, … so when the maximum allowed content length is reached, we won’t get stuck!
This should also work for the keydown
, but it logs all keys, so we would then we have to add exceptions for the allowed keys.
Related Posts:
- Add popup window to TinyMCE buttons
- TinyMCE editor is breaking my beautiful HTML
- How to replace the content of tinyMCE editor in both text and visual mode using jQuery?
- Is it possible to create nested lists in the WYSIWYG editor?
- TinyMCE Anchor Button not showing
- How to keep non-breaking spaces in the visual editor?
- Is there a way to prevent the Editor from modifying my HTML
- How to disable TinyMCE 4 keyboard shortcuts
- How to customize the symbols that appear in the Visual Editor insert custom character
- Pasting code into pre-formatted text in Visual Editor not working in 3.3.1
- Add Shortcode inline inside Gutenberg block
- How to make WordPress and TinyMCE accept tags wrapping block-level elements as allowed in HTML5?
- Visual Editor freezing on text highlight since 4.3
- tinyMCE duplicates previous block element when pressing return (visual editor)
- WordPress visual editor broke due to non standard port?
- Customising the WordPress TinyMce editor and it’s buttons
- Enable Visual Editor In Comments On CPT Edit Page
- Text cut off after the character 𪇆 in TinyMCE
- Adding image to visual editor popup for shortcode with wp.media and wp.mce: changing image duplicates shortcode
- Change Default Font Size and Remove Unwanted Font Sizes in TinyMCE
- TinyMce in WordPress – Getting the “fullscreen” button to stay on the right when customising button layout
- Added custom styles to Visual Editor. Classes are appended and not replaced as intended
- Preserving tabs and line breaks in when switching from HTML to Visual Editor
- How to disable formatting
- Add table button in editor without Plugin
- Make Textarea a TinyMCE (editor box)
- How to get line breaks to translate to paragraphs?
- TinyMCE Visual Blocks plugin set Show blocks option for all users
- Custom TinyMCE style formats disabled
- Visual editor not showing all table rows
- Is it possible to disable the image alignment options in the post editor?
- Open Insert/edit link popup
- Change syntax styling of TinyMCE HTML Text Editor
- More than one TinyMCE (wp_editor) with different $settings[‘drag_drop_upload’] values breaks
- Customer Support: TinyMCE stopped working (on some computers)
- customize tiny MCE blockqute
- Keyup events in tinymce editor not working
- How to force insertion in editor
- Stop editor from adding “amp;” after every “&”
- Visual Editor is blank – 404 for plugin js
- Visual composer causing conflict with TinyMCE [closed]
- TinyMCE: Move buttons from 2nd row to top row
- enable TinyMCE for comment forms
- Best Browser for Editing Posts
- TinyMCE strips off the href tag inside span, if i change from text to visual
- Adding a Media Button to the WordPress Content Editor
- clasic editor – article categories customization?
- How can I change TinyMCE’s default block format?
- Load WordPress Editor .css on Front End
- “Formats” Select Menu in WP Editor doesn’t show up with correct colour
- How to force wp excerpt to use br tag?
- Adding microdata using Structured Data Markup Helper HTML
- How to modify VisualComposer’s TinyMCE editor only for a specific shortcode
- Preventing tinyMCE from auto formatting selected blocks of content
- wp_insert_post() dont post content like i need it :(
- WordPress Started Executing Code Inside PRE Tags Even They Are Properly Escaped
- Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
- How to add “Insert/Edit link” button in custom popup tinymce window?
- How to disable TinyMCE from removing span tags
- Forcing reload of editor-style.css
- How to get the input of a TinyMCE editor when using on the front-end?
- Enqueue Script After TinyMCE initialized
- Unable to add “code” button to TinyMCE toolbar
- Add unique class or ID information to tinyMCE
- Add a button to tinyMCE editor on Custom Post Type
- HTML5, WordPress and Tiny MCE issue – wrapping anchor tag around div results in funky output
- Registering custom TinyMCE buttons, for admin area, to work with custom instances of wp_editor
- Adding TinyMCE custom buttons when using teeny_mce_before_init
- Add visual editor to Media Edit Screen
- Disabling TinyMCE keyboard shortcuts altogether
- Making a custom widget that includes a tinymce and works in Site Origin Page Builder
- TinyMCE strips line breaks on mceAddControl
- Should the WP post editor B (bold) button be inserting a tag instead of in HTML5?
- TinyMCE Editor removing and and putting instead
- Add TinyMCE editor to windowManager textbox
- unwanted and tags in text editor
- Limit Block format tags in WordPress wp_editor
- Custom settings page TinyMce: no formatting when echoing value of editor
- How to reset ‘Advance’ tab on table property?
- Add drop down in wordpress tiny mce editor pop up
- Prevent the Editor From Moving My
- TinyMCE Advanced list type drop-down
- editor text cut off when using 2 spaces (after periods)
- Advanced tinyMCE insert link error [closed]
- Removing tags around tags
- TinyMCE not loading in IE8
- Getting shortcode attribute values and shortcode content with JavaScript regex
- How do I add multiple buttons to Tiny MCE in a single plugin?
- Keyboard shortcut for headings on safari
- wp_tiny_mce function not found
- Replace text by icon in TinyMCE toolbar
- TinyMCE Advanced Link Class List on the main editor
- Changing code with ( ) when author updates their post (TinyMCE)
- WordPress Editor without buttons
- How do I externalize JQuery from my Tinymce Modal Dialog’s html and Enqueue the JS File to see JQuery
- Tinymce doesnt appear
- Remove heading tags on line break
- tinymce modal and I18n strings methods
- WordPress WYSIWYG editor on demand, responsive
- Sorting UL Listing Within the TinyMCE Visual Editor in WordPress