53

実行時にtinymceテキストエリアを無効にするか、読み取り専用にする必要があります。

4

13 に答える 13

64

構成パラメーターreadonlyを使用する

tinyMCE.init({
        ...
        theme : "advanced",
        readonly : 1
});

ここにデモへのリンクがあります。

更新: ユーザーがエディターでコンテンツを編集できないようにするためにできることは、エディターの iframe 本体の contenteditable 属性を false に設定することです。

tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
于 2012-12-14T15:43:53.090 に答える
53

バージョン 4.3.x 以降では、読み取り専用モードで以下のコードを使用できます

tinymce.activeEditor.setMode('readonly');

デザインモードの場合:

tinymce.activeEditor.setMode('design'); 
于 2016-03-14T08:40:25.560 に答える
25

エディターが 1 つしかない場合、これは機能します。

tinymce.activeEditor.getBody().setAttribute('contenteditable', false);

複数のエディターがある場合は、テキストエリアの ID でエディターを選択する必要があります。

tinyMCE.get('textarea_id').getBody().setAttribute('contenteditable', false);
于 2014-03-17T16:31:26.990 に答える
15

Thariama のソリューションは、ページ上のすべての TinyMCE テキストエリアを読み取り専用に設定します。

私が見つけた最良の解決策は、読み取り専用属性を持つフィールドを読み取り専用に設定する Magnar Myrtveit によって投稿されました。コードは次のとおりです。

tinyMCE.init({
    ...
    setup: function(ed) {
        if ($('#'+ed.id).prop('readonly')) {
            ed.settings.readonly = true;
        }
    }
});
于 2013-08-16T16:54:16.137 に答える
2

無効にするには、次のコマンドを呼び出します。

tinymce.EditorManager.execCommand('mceToggleEditor', true, tinymceId);

そして、エディターを再度有効にするには、このコマンドを再度呼び出すことができます。

' mceToggleEditor ' コマンドは、テキストエリアとエディター インスタンスを表示または非表示にすることで、WYSIWYG モードのオンとオフを切り替えます。これは mceAddControl または mceRemoveControl と同じではありません。インスタンスがまだそこにあり、初期化されていないため、この方法の方が高速です。

上記のコマンドのリンク: http://archive.tinymce.com/wiki.php/TinyMCE3x:Command_identifiers

于 2016-01-13T12:55:37.810 に答える
1

あなたが使用することができます

this.getBody().setAttribute('contenteditable', false);

完全なソリューションを見てください、私のサーバー側はAsp.net MVC

 setup: function (ed) {
        ed.on('init', function () {
            this.execCommand("fontSize", false, "17px");
            $("html,body").scrollTop(0);
            @if (ViewBag.desableEdit != null && ViewBag.desableEdit == true)
            {
                <text>
                    this.getBody().setAttribute('contenteditable', false);
                </text>
            }

        });

server side condition返された HTML で削除されるものがある場合は、それを行う別の方法

 tinymce.init({
    selector: ... ,
    ....
    @if (ViewBag.desableEditExseptExportNumber != null && ViewBag.desableEditExseptExportNumber == true)
    {
         <text>
              readonly: 1,
         </text>
    }
    language: 'ar',
    ....});
于 2016-10-19T12:24:24.557 に答える
0

おそらく、このコード行は、iframe を使用する他のブラウザーで役立つでしょう。

tinymce.activeEditor.getBody().contenteditable = false

よろしく!

于 2013-10-04T06:23:11.477 に答える