最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TinyMCE setContent does not clear undo history - Stack Overflow

programmeradmin0浏览0评论

I'm using angular tinyMCE directive in a form. After submit I use this mand to clear the textarea:

tinyMCE.activeEditor.setContent('');

and also this: $scope.tinymceModel =''; to clear the model. My form is inside a modal. When I open the modal again the textarea seems clear but the "undo" button in TinyMCE is active and if I click on it I can see the old content. Is it possible reset and clear the TinyMCE undo history? This is the html part:

<textarea id="elm1" ui-tinymce="tinymceOptions" ng-model="tinymceModel" auto-focus id="elm1" rows="8" cols="100"></textarea>

and this is the options

$scope.tinymceModel = '';
        $scope.tinymceOptions = {
            height: 420,
            language:'it',
            theme: "modern",
            plugins: [
                "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
                "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                "save table contextmenu directionality emoticons template paste textcolor"
            ],
            content_css: "css/partials/content.css",
            toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage",
            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'}
            ],
            setup : function(ed){
                ed.on('keyup', function(e) {
                    get_ed_content = tinymce.activeEditor.getContent();
                    if(get_ed_content != '' && get_ed_content != undefined && get_ed_content != null) {
                        $scope.tinyHasContent = true;
                    } else {
                        $scope.tinyHasContent = false;
                    }
                });
                ed.on('init', function()
                {
                    this.getDoc().body.style.fontSize = '1.2em';
                });

            }
        };

thanks

I'm using angular tinyMCE directive in a form. After submit I use this mand to clear the textarea:

tinyMCE.activeEditor.setContent('');

and also this: $scope.tinymceModel =''; to clear the model. My form is inside a modal. When I open the modal again the textarea seems clear but the "undo" button in TinyMCE is active and if I click on it I can see the old content. Is it possible reset and clear the TinyMCE undo history? This is the html part:

<textarea id="elm1" ui-tinymce="tinymceOptions" ng-model="tinymceModel" auto-focus id="elm1" rows="8" cols="100"></textarea>

and this is the options

$scope.tinymceModel = '';
        $scope.tinymceOptions = {
            height: 420,
            language:'it',
            theme: "modern",
            plugins: [
                "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
                "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                "save table contextmenu directionality emoticons template paste textcolor"
            ],
            content_css: "css/partials/content.css",
            toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage",
            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'}
            ],
            setup : function(ed){
                ed.on('keyup', function(e) {
                    get_ed_content = tinymce.activeEditor.getContent();
                    if(get_ed_content != '' && get_ed_content != undefined && get_ed_content != null) {
                        $scope.tinyHasContent = true;
                    } else {
                        $scope.tinyHasContent = false;
                    }
                });
                ed.on('init', function()
                {
                    this.getDoc().body.style.fontSize = '1.2em';
                });

            }
        };

thanks

Share Improve this question edited Jul 26, 2016 at 15:01 Michael Fromin 13.8k2 gold badges23 silver badges34 bronze badges asked Jul 26, 2016 at 14:22 Atlas91Atlas91 5,90417 gold badges75 silver badges148 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

After you set your new content add a call to undoManager.clear(). Something like this:

tinymce.activeEditor.setContent('');
tinymce.activeEditor.undoManager.clear()

This will clear the undo history for the active editor so you can't go back to the prior content.

发布评论

评论列表(0)

  1. 暂无评论