EDITOR: oops - I thought this was another question I was considering that was specific to WordPress + TinyMCE, I don't think so. Although I will leave the answer here, as it may be useful to others.
The right way to do this would be to add tinyMCE init using the WordPress filter. For example:
PHP (in functions.php or another place that executes when the page loads):
add_action( 'init', 'register_scripts' ); function register_scripts(){ if ( is_admin() ) { wp_register_script( 'admin-script', get_stylesheet_directory_uri() . "/js/admin/admin.js", array('jquery'), false, true ); } } add_action( 'admin_enqueue_scripts', 'print_admin_scripts' ); function print_admin_scripts() { wp_enqueue_script('admin-script'); } add_filter( 'tiny_mce_before_init', 'my_tinymce_setup_function' ); function my_tinymce_setup_function( $initArray ) { $initArray['setup'] = 'function(ed){ ed.onChange.add(function(ed, l) { tinyOnChange(ed,l); }); }'; return $initArray; }
JavaScript (/js/admin/admin.js)
(function($){ window.tinyOnChange = function(ed, l){ console.log('Editor contents was modified. Contents: ' + l.content); } }(jQuery);
This is tested and works in WordPress 3.9 (although I just get console output:
Deprecated TinyMCE API call: <target>.onChange.add(..)
But this is because you are trying to use outdated tinyMCE code. This method still works to change any of the tinyMCE init parameters - I am currently using it for init_instance_callback and it works great.
-Thomas
tsdexter
source share