Тариама ответил идеально.Я использую JMuery соединитель tinyMCE для некоторых из моих страниц, и у меня есть несколько экземпляров tinyMCE на странице.Я сделал некоторые изменения, но по сути это то же самое.Я создал текстовое поле на странице, чтобы люди могли предоставить свой собственный CSS.Кроме того, мне нужно было изменить некоторые правила CSS на лету ...
// function to change tinyMCE css on the fly
function checkCustomCSS() {
var $css = $('#page_css'),
newcss;
if ($css.val().length > 0) {
// since front end, we are wrapping their HTML in a wrapper and
// the tinyMCE edit iFrame is just using <body>, we need to change
// some rules so they can see the changes
newcss = $css.val().replace('#content_wrapper', 'body');
// loop through each tinyMCE editor and apply the code changes
// You could check the editor.id to make sure that the correct
// editor gets the appropriate changes.
$.each(tinyMCE.editors, function() {
var $this = $(this),
editorID = $this[0].id,
$ifrm = $('#' + editorID+ '_ifr'),
cwin, head, sheet;
if ($ifrm.length > 0 /* && editorID === 'OUR_EDITOR_ID_NAME' */) {
cwin = $ifrm[0].contentWindow;
head = cwin.document.getElementsByTagName("head");
if (!head.length) {
return;
}
sheet = cwin.document.createElement("style");
sheet.type = "text/css";
head[0].appendChild(sheet);
try {
if (typeof sheet.styleSheet !== "undefined") {
sheet.styleSheet.cssText = newcss;
} else {
sheet.appendChild(cwin.document.createTextNode(newcss));
sheet.innerHTML = newcss;
}
} catch (e) {}
}
});
}
}
Затем в вызове tinyMCE init, который я добавил, и вызов onInit для изменения настроек #page_css, например:
oninit: function() {
$('#page_css').on('change', function() {
checkCustomCSS();
});
}
Работает как шарм.