Using jQuery I’m trying to manipulate the WordPress content editor, which uses TinyMCE inside of an iframe. I can’t seem to get the following code to work as intended:
jQuery(document).ready(function($) {
$('#content_ifr').ready(function() {
$('#content_ifr').contents().find('body').css('background-color', '#f33');
});
Regardless of whether I use “.ready()” or “.load()”, the event will fire before the TinyMCE editor (the body of the iframe) is completely finished loading.
However, the following code will work if I wait for the iframe to load before manually clicking the title textbox to fire the click event:
jQuery(document).ready(function($) {
$('#title').click(function() {
$('#content_ifr').contents().find('body').css('background-color', '#f33');
});
I’ve searched exhaustively on the subject of jQuery and iFrames, and it seems it’s a hit or miss depending on the situation. Some code works for some people and not for others.
Does anyone know of a way to get the first code snippet to fire after the TinyMCE iframe body is completely finished loading? Because it’s just the WordPress content editor, the iframe content is on the same domain.
What I really want to do is add a class to the body element in the iframe via .addClass()
jQuery(document).ready(function($) {
$('#content_ifr').ready(function() {
$('#content_ifr').contents().find('body').addClass('ui-droppable');
});
so that I can apply the drag n’ drop code in the following tutorial:
http://skfox.com/2008/11/26/jquery-example-inserting-text-with-drag-n-drop/
You can use the
tiny_mce_before_init
hook to add a class to the body before tinymce.initI use this function to access or style iframe (inside tinymce) in Wordpess:
this script is added to wordpress dashboard scripts, and detects while TINYMCE iframe is loaded, then actions to it.
Have a look at your tinymce configuration. All you need to so is to use the “setup”-setting and set the onInit-Handler there. Here is an example: