繁体   English   中英

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

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

我在一页上实现了4个TinyMCE编辑器。 当用户离开TinyMCE编辑器并将编辑器的html放在textarea中时,我想获取编辑器ID。 模糊时,我可以获取编辑器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>triggerSave()但是除了调试以外,您将不需要这些console.log()调用。

我检查所有对象及其tinymce的值,并通过以下方式获得活动的编辑器ID

tinymce.EditorManager.activeEditor.editorId;

这将返回活动的编辑器ID

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM