加载多个 TinyMCE 实例会冻结浏览器,解决方案吗?

发布于 2024-12-05 23:03:42 字数 3300 浏览 4 评论 0原文

我有一个页面同时运行多个tinymce 实例,并且每当加载时它都会冻结浏览器。我需要等待不少于 15 秒才能再次使用浏览器。我已经在 IE9、FF6 和 Chrome 上对此进行了测试,所有这些在加载时都会冻结一段时间。

我怎样才能防止这种冻结发生?我在一页中至少有 10 个带有tinymce 的文本区域。计算机在具有 4GB RAM 的 core2duo 上运行,没有运行任何其他程序,但这并不重要,因为即使在较低规格的 PC 上它也应该可以工作。

编辑添加 JS 代码以加载 TinyMCE。

<script type="text/javascript">
var myTextbox = "10 name of textarea here";

tinyMCE.init({
    // General options
    mode : "exact",
    elements: myTextbox,
    theme : "advanced",
    plugins : "paste,ibrowser",
    paste_remove_styles: true,
    paste_auto_cleanup_on_paste : true,
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
    // Theme options
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "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,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,|,charmap,emotions,iespell,media,advhr,",
    theme_advanced_buttons5 : "pastetext,pasteword,selectall,iuploader,upload_status",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,

    setup : function(ed) {
    //IMAGE UPLOADER BUTTON 
    ed.addButton('iuploader', {
        title : 'Upload Image',
        image : '/www/images/admin/post_button_image_upload.gif',
        onclick : function() {
            load_image_uploader(this.id);
         }
      }),
    ed.addButton('upload_status', {
        title : 'Upload Status',
        image : '',
        onclick : function() {

         }
      });
    },

    // Content CSS
    content_css : "/www/js/tiny_mce/css/content.css",

    // Drop lists for link/image/media/template dialogs
    template_external_list_url : "lists/template_list.js",
    external_link_list_url : "lists/link_list.js",
    external_image_list_url : "lists/image_list.js",
    media_external_list_url : "lists/media_list.js",

    // Style formats
    style_formats : [
        {title : 'Bold text', inline : 'b'},
        {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
        {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
        {title : 'Example 1', inline : 'span', classes : 'example1'},
        {title : 'Example 2', inline : 'span', classes : 'example2'},
        {title : 'Table styles'},
        {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
    ],

    // Replace values for the template plugin
    template_replace_values : {
        username : "Some User",
        staffid : "991234"
    }

});

I have a page with multiple tinymce instances running at the same time and it's freezing the browser whenever it loads. It's taking not less than 15 seconds of waiting before I could use the browser again. I've tested this on IE9, FF6, and Chrome and all of them are freezing for some time while it is loading.

How could I prevent this freezing from happening? I have at least 10 textarea with tinymce attached to it in one page. Computer is running on core2duo with 4GB of RAM without any other program running, but this shouldn't matter as its supposed to work even with a lower spec PC.

Edit add JS code to load TinyMCE.

<script type="text/javascript">
var myTextbox = "10 name of textarea here";

tinyMCE.init({
    // General options
    mode : "exact",
    elements: myTextbox,
    theme : "advanced",
    plugins : "paste,ibrowser",
    paste_remove_styles: true,
    paste_auto_cleanup_on_paste : true,
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
    // Theme options
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "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,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,|,charmap,emotions,iespell,media,advhr,",
    theme_advanced_buttons5 : "pastetext,pasteword,selectall,iuploader,upload_status",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,

    setup : function(ed) {
    //IMAGE UPLOADER BUTTON 
    ed.addButton('iuploader', {
        title : 'Upload Image',
        image : '/www/images/admin/post_button_image_upload.gif',
        onclick : function() {
            load_image_uploader(this.id);
         }
      }),
    ed.addButton('upload_status', {
        title : 'Upload Status',
        image : '',
        onclick : function() {

         }
      });
    },

    // Content CSS
    content_css : "/www/js/tiny_mce/css/content.css",

    // Drop lists for link/image/media/template dialogs
    template_external_list_url : "lists/template_list.js",
    external_link_list_url : "lists/link_list.js",
    external_image_list_url : "lists/image_list.js",
    media_external_list_url : "lists/media_list.js",

    // Style formats
    style_formats : [
        {title : 'Bold text', inline : 'b'},
        {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
        {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
        {title : 'Example 1', inline : 'span', classes : 'example1'},
        {title : 'Example 2', inline : 'span', classes : 'example2'},
        {title : 'Table styles'},
        {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
    ],

    // Replace values for the template plugin
    template_replace_values : {
        username : "Some User",
        staffid : "991234"
    }

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

离去的眼神 2024-12-12 23:03:43

问题是 TinyMCE 加载的 iframe 数量与您的实例一样多。对于您的情况,更好的选择可能是使用内联版本 https://www.tiny。云/文档/演示/内联/

The problem is that TinyMCE loads as many iframes as your instances. A better option in your case could be to use the inline version https://www.tiny.cloud/docs/demo/inline/

心作怪 2024-12-12 23:03:42

Brett Henderson 是对的,加载 10 个实例需要时间。但是,您永远无法一次编辑 10 个,因此仅针对用户想要使用的区域打开 TinyMCE 即可实现。

单击时为所有文本区域创建 TinyMCE 实例的代码:

$('textarea').each(function(e) {
    e.addEvent( 'click', function() {
        tinyMCE.execCommand('mceAddControl', false, e.getProperty('id')) ;
    });
});

并将模式更改为无:

tinyMCE.init({
    // General options
    mode : "none",

    /* 
       other options etc 
    */

});

Brett Henderson is right, loading 10 instances takes time. But, you'll never edit 10 at once, so opening TinyMCE only for the areas the user wants to work with will get you there.

Code to create TinyMCE instance for all textareas on click:

$('textarea').each(function(e) {
    e.addEvent( 'click', function() {
        tinyMCE.execCommand('mceAddControl', false, e.getProperty('id')) ;
    });
});

and change the mode to none:

tinyMCE.init({
    // General options
    mode : "none",

    /* 
       other options etc 
    */

});
唠甜嗑 2024-12-12 23:03:42
tinyMCE.init({
            mode : "exact",
            elements : "ajaxfilemanager, ajaxfilemanager_1",
            theme : "advanced", ....



<textarea id="ajaxfilemanager" name="ajaxfilemanager" style="width: 100%; height: 500px" ></textarea>
<textarea id="ajaxfilemanager1" name="ajaxfilemanager_1" style="width: 100%; height: 500px" ></textarea>
tinyMCE.init({
            mode : "exact",
            elements : "ajaxfilemanager, ajaxfilemanager_1",
            theme : "advanced", ....



<textarea id="ajaxfilemanager" name="ajaxfilemanager" style="width: 100%; height: 500px" ></textarea>
<textarea id="ajaxfilemanager1" name="ajaxfilemanager_1" style="width: 100%; height: 500px" ></textarea>
淡淡绿茶香 2024-12-12 23:03:42

我使用点击事件在点击的文本区域上加载tinyMCE,这帮助我在同一页面上使用多个tinyMCE编辑器而无需冻结浏览器,这可能不是正确的方法,但它对我有用。代码:

            $('textarea').click(function(){
                $(this).addClass("tinyopen");
                //tinyMCE -------------
                    tinyMCE.init({

                        mode : "specific_textareas",
                        editor_selector : "tinyopen",

                        //  -----  Here comes your plugins and themes --------- //
                        //                                                      //  
                        //                                                      //  
                        //                                                      //
                        //  --------------------------------------------------- //

                        content_css : "path to css"

                    });
                //tinyMCE -------------
            });

i use a click event to load tinyMCE on the clicked textarea, this helped me to use multiple tinyMCE editors on the same page without freezing the browser, it might not be the right way but it works for me. code:

            $('textarea').click(function(){
                $(this).addClass("tinyopen");
                //tinyMCE -------------
                    tinyMCE.init({

                        mode : "specific_textareas",
                        editor_selector : "tinyopen",

                        //  -----  Here comes your plugins and themes --------- //
                        //                                                      //  
                        //                                                      //  
                        //                                                      //
                        //  --------------------------------------------------- //

                        content_css : "path to css"

                    });
                //tinyMCE -------------
            });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文