実行時にtinymceテキストエリアを無効にするか、読み取り専用にする必要があります。
13 に答える
構成パラメーターreadonlyを使用する
tinyMCE.init({
...
theme : "advanced",
readonly : 1
});
ここにデモへのリンクがあります。
更新: ユーザーがエディターでコンテンツを編集できないようにするためにできることは、エディターの iframe 本体の contenteditable 属性を false に設定することです。
tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
バージョン 4.3.x 以降では、読み取り専用モードで以下のコードを使用できます
tinymce.activeEditor.setMode('readonly');
デザインモードの場合:
tinymce.activeEditor.setMode('design');
エディターが 1 つしかない場合、これは機能します。
tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
複数のエディターがある場合は、テキストエリアの ID でエディターを選択する必要があります。
tinyMCE.get('textarea_id').getBody().setAttribute('contenteditable', false);
無効にするには、次のコマンドを呼び出します。
tinymce.EditorManager.execCommand('mceToggleEditor', true, tinymceId);
そして、エディターを再度有効にするには、このコマンドを再度呼び出すことができます。
' mceToggleEditor ' コマンドは、テキストエリアとエディター インスタンスを表示または非表示にすることで、WYSIWYG モードのオンとオフを切り替えます。これは mceAddControl または mceRemoveControl と同じではありません。インスタンスがまだそこにあり、初期化されていないため、この方法の方が高速です。
上記のコマンドのリンク: http://archive.tinymce.com/wiki.php/TinyMCE3x:Command_identifiers
あなたが使用することができます
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',
....});
おそらく、このコード行は、iframe を使用する他のブラウザーで役立つでしょう。
tinymce.activeEditor.getBody().contenteditable = false
よろしく!