在tinymce编辑器中模糊时如何获取父iFrame ID?

How can get the parent iFrame ID when blur in tinymce editor?

我在一个页面上实现了 4 个 TinyMCE 编辑器。我想在用户离开 TinyMCE 编辑器并将编辑器的 html 放入文本区域时获取编辑器 ID。在 blur 上,我可以获得编辑器 html。但我无法在 Firefox 和 IE 中找到 iFrame ID。我试过这段代码。

tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    plugins : "table,insertdatetime,fullscreen,searchreplace,emotions,paste,",
    selector: "#vereinbarungen",
    selector: "#narration",
    theme_advanced_buttons1 : "insertdate,inserttime,|,hr,emotions,|,search,replace,|,cut,copy,paste,pastetext,pasteword,|,forecolor,backcolor,|,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,|,fullscreen", 
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "bottom",
    theme_advanced_toolbar_align : "left",
    extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
    plugin_insertdate_dateFormat : "%d.%m.%Y",
    plugin_insertdate_timeFormat : "%H:%M:%S",
    setup : function(ed) {    
        ed.onInit.add(function(ed, event) {
            var dom = ed.dom,
            doc = ed.getDoc(),
            el = doc.content_editable ? ed.getBody() : (tinymce.isGecko ? doc : ed.getWin());
            tinymce.dom.Event.add(el, 'blur', function(e) {

                //this is the targeted iframe id this works in chrome but not works in other browsers.

                target_id = el.frameElement.id;
                html = $(ed.getBody()).html();
            });
        });
    },

});

当我使用 Chrome 尝试此代码时,我得到了 target_id 但是当我尝试使用其他浏览器时 el.frameElement 是未定义的。

这个问题的解决方案是什么?

如果我理解你的问题,当编辑器模糊时你想做的是用编辑器的当前值更新基础 <textarea>

TinyMCE 中的 triggerSave() API 将自动执行您想要的操作,而无需执行您当前正在执行的任何手动 JavaScript 工作。

示例如下:

关键代码是这样的:

setup: function (editor) {
    editor.on('blur', function (e) {
        console.log('Triggering a Save');
        tinymce.triggerSave();
        console.log(document.getElementById('content').value);
    });
}

我使用 JavaScript 来显示 triggerSave() 调用完成后 <textarea> 中的内容,但除了调试之外,您不需要这些 console.log() 调用。

我检查了 tinymce 的所有对象及其值,并通过

获得了活动编辑器 ID

tinymce.EditorManager.activeEditor.editorId;

此 return 活动编辑器 ID