【问题标题】:tinyMce activeeditor is null on postbacktinyMce activeeditor 在回发时为空
【发布时间】:2013-06-07 08:35:38
【问题描述】:

我正在使用tinymce editor 到具有确切ID 的文本区域。它在页面加载时工作正常。 但是,当我单击 asp 按钮“保存”后返回以将数据保存在 DB 中时,活动编辑器变为空且不保留其值。 如何克服这个问题?

我在页面加载中的 tinyMce 初始化代码是

tinyMCE.init({
mode: "exact",
elements : "divLabTemplateTree",
encoding: "xml",
convert_urls: false,
theme: "advanced",
width:"300",
height:"400",
skin : "o2k7",
plugins: "spellchecker,pagebreak,style,layer,table,advhr,advimage,advlink,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras",
extended_valid_elements: "iframe[src|width|height|name|align]",
theme_advanced_buttons1: "spellchecker,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,|,print,fullscreen",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,media,advhr,|",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_path_location: "bottom",
theme_advanced_resizing: true,
theme_advanced_resize_horizontal: false,    
dom_loaded : 1,
theme_advanced_styles: "Link to Image: lightbox;Image Right Border: rightbordered;Image Left Border: leftbordered;Darker Text: darker",
setup: function (ed) {
    ed.onSaveContent.add(function (i, o) {
        o.content = o.content.replace(/&#39/g, "&apos");
    });

    ed.onInit.add(function(ed) {
        tinyMCE.execCommand("mceAddControl", true, "divLabTemplateTree");
    });

    }
});

我正在设置它的值

if(tinyMCE.activeEditor != null)
{
    tinyMCE.activeEditor.setContent("bbbbbbbbbbbbbbb");
}

【问题讨论】:

    标签: c# asp.net tinymce


    【解决方案1】:

    当一个页面被初始化时 tinyMCE.activeEditor 为 null 直到用户明确点击进入编辑器的那一刻。

    这里推荐使用tinymce.get('your_editor_id')。您的编辑器等于初始化编辑器的 textarea id。如果此 textarea(或其他 html 源代码)没有 id,则默认使用 content

    【讨论】:

    • tinymce.get('your_editor_id').setContent(Text) 没有在回发时将文本分配给编辑器。
    • 您需要插入自己的 id。顺便提一句。你在用 tinymce4 吗?
    • 我只在这里使用我的 id 我只是为了语法而写的。我正在使用tinymce3.7
    • @Thariama 我遇到了与 OP 相同的问题,但您的解决方案为我返回了 null(在 tinyMCE 4.1.5 上)
    • Juicy:请记住,tinymce.get('your_editor_id') 仅在编辑器初始化后才能工作(您可以在此处使用 oninit 处理程序在初始化后执行操作),当然您需要在此处插入您自己的编辑器 ID,而不是“your_editor_id”。
    猜你喜欢
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多