Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  93] [ 2]  / answers: 1 / hits: 16257  / 13 Years ago, fri, april 22, 2011, 12:00:00

I'm trying to write a Wordpress plugin. I will get counts words which in WP's Tinymce editor.
Basically, it's a word counter which counting long of your post and giving you this message in a meta box




Your post has 450 words




My just problem is getting words from Tinymce via javascript. This isn't working :



document.getElementById('content')


Tinymce's content's id is content . But this code returning NULL. I couldn't find valid id name for Tinymce.



In shortly, other all codes are ready, just i can't get words from Wordpress' WYSIWYG editor.



Thanks.


More From » wordpress

 Answers
14

Try:



tinymce.activeEditor.getContent();


or



tinymce.editors.content.getContent();


Where content is the id of your textarea.



Similarly, if you wanted to get just the selected (highlighted) text in the TinyMCE text area you would do:



tinymce.activeEditor.selection.getContent();


The full API is here: http://tinymce.moxiecode.com/wiki.php/API3:class.tinymce.Editor



TinyMCE also offers a lot of events you can bind to, particularly in your case the keyup, keydown, and keypressed events.



Be sure to call this stuff only after TinyMCE has loaded on the page.


[#92602] Thursday, April 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
terrence questions
Sat, Jun 5, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
;